豁然明白的囧事 之 执行mvn:clean deploy提示Unauthorized

Posted buguge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了豁然明白的囧事 之 执行mvn:clean deploy提示Unauthorized相关的知识,希望对你有一定的参考价值。

对工程里一个用来对外提供jar的module进行deploy。

直接在IDEA的maven面板里执行deploy是没问题的,可以正常发布到私服上。而在执行clean deploy命令时,却总是不成功,提示Return code is: 401, ReasonPhrase: Unauthorized.

为什么我没权限呢?我可以deploy的呀!

迟疑一刻,才豁然明白,maven服务器自然是要做权限控制的,普通用户都能删除仓库里的包,岂不是太可怕了。嘿嘿~

 

 

附pom配置:

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://192.168.40.196:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://192.168.40.196:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

 

附build错误:

"C:Program FilesJavajdk1.8.0_40injava.exe" -Dmaven.multiModuleProjectDirectory=D:SourceProjectzhengheoms_baseomsbase-rpcapi -Dmaven.home=D:Javaapache-maven-3.3.3 -Dclassworlds.conf=D:Javaapache-maven-3.3.3inm2.conf "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2018.3.4libidea_rt.jar=35487:C:Program FilesJetBrainsIntelliJ IDEA 2018.3.4in" -Dfile.encoding=UTF-8 -classpath D:Javaapache-maven-3.3.3ootplexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3.4 clean deploy -DskipTests
                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building omsbase-rpcapi 1.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------

[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ omsbase-rpcapi ---
[INFO] Deleting D:SourceProjectzhengheoms_baseomsbase-rpcapi	arget

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ omsbase-rpcapi ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 26 source files to D:SourceProjectzhengheoms_baseomsbase-rpcapi	argetclasses

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ omsbase-rpcapi ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ omsbase-rpcapi ---
[INFO] Building jar: D:SourceProjectzhengheoms_baseomsbase-rpcapi	argetomsbase-rpcapi-1.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ omsbase-rpcapi ---
[INFO] Installing D:SourceProjectzhengheoms_baseomsbase-rpcapi	argetomsbase-rpcapi-1.0.1-SNAPSHOT.jar to D:workspacem3comemaxzhengheomsbase-rpcapi1.0.1-SNAPSHOTomsbase-rpcapi-1.0.1-SNAPSHOT.jar
[INFO] Installing D:SourceProjectzhengheoms_baseomsbase-rpcapipom.xml to D:workspacem3comemaxzhengheomsbase-rpcapi1.0.1-SNAPSHOTomsbase-rpcapi-1.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ omsbase-rpcapi ---
Downloading: http://192.168.40.196:8081/nexus/content/repositories/snapshots/com/emax/zhenghe/omsbase-rpcapi/1.0.1-SNAPSHOT/maven-metadata.xml
Downloaded: http://192.168.40.196:8081/nexus/content/repositories/snapshots/com/emax/zhenghe/omsbase-rpcapi/1.0.1-SNAPSHOT/maven-metadata.xml (780 B at 0.9 KB/sec)
Uploading: http://192.168.40.196:8081/nexus/content/repositories/snapshots/com/emax/zhenghe/omsbase-rpcapi/1.0.1-SNAPSHOT/omsbase-rpcapi-1.0.1-20200506.101246-7.jar
Uploading: http://192.168.40.196:8081/nexus/content/repositories/snapshots/com/emax/zhenghe/omsbase-rpcapi/1.0.1-SNAPSHOT/omsbase-rpcapi-1.0.1-20200506.101246-7.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.762 s
[INFO] Finished at: 2020-05-06T18:12:47+08:00
[INFO] Final Memory: 57M/516M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project omsbase-rpcapi: Failed to deploy artifacts: Could not transfer artifact com.emax.zhenghe:omsbase-rpcapi:jar:1.0.1-20200506.101246-7 from/to snapshots (http://192.168.40.196:8081/nexus/content/repositories/snapshots/): Failed to transfer file: http://192.168.40.196:8081/nexus/content/repositories/snapshots/com/emax/zhenghe/omsbase-rpcapi/1.0.1-SNAPSHOT/omsbase-rpcapi-1.0.1-20200506.101246-7.jar. Return code is: 401, ReasonPhrase: Unauthorized.

 

附maven私服仓库截图:

技术图片

 

以上是关于豁然明白的囧事 之 执行mvn:clean deploy提示Unauthorized的主要内容,如果未能解决你的问题,请参考以下文章

Maven - 为啥在“mvn clean”之后我需要在“mvn package”之前执行“Maven Update Project”?

mvn clean package install deploy

此环境中不提供编译器。执行 mvn clean package 时

如何在eclipse中使用mvn clean install

为啥执行“mvn clean package”来构建 Spark 失败并显示“某些 Enforcer 规则失败”?

Eclipse编译运行没问题,但执行mvn clean install跑单元测试失败的原因解析