将工程里一个基础module打包发布到公司内部的maven仓库服务器。
直接在IDEA的maven面板里执行deploy是没问题的,可以正常发布到私服上。而在执行clean deploy命令时,却总是不成功,提示Return code is: 401, ReasonPhrase: Unauthorized.
为什么我没权限呢?
我可以deploy的呀!检查maven的settings.xml文件已经配置了servers节点。
迟疑一刻,才豁然明白,maven服务器自然是要做权限控制的,普通用户都能删除仓库里的包,岂不是太可怕了。嘿嘿~
附pom配置distributionManagement:
pom里必须配置distributionManagement节点。否则会构建失败,错误信息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project omsbase-rpcapi:
Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
<distributionManagement> <repository> <id>releasesid> <url>http://192.168.40.196:8081/nexus/content/repositories/releasesurl> repository> <snapshotRepository> <id>snapshotsid> <url>http://192.168.40.196:8081/nexus/content/repositories/snapshots/url> snapshotRepository> distributionManagement>
附build错误:
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\SourceProject\zhenghe\oms_base\omsbase-rpcapi -Dmaven.home=D:\Java\apache-maven-3.3.3 -Dclassworlds.conf=D:\Java\apache-maven-3.3.3\bin\m2.conf "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\lib\idea_rt.jar=35487:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.4\bin" -Dfile.encoding=UTF-8 -classpath D:\Java\apache-maven-3.3.3\boot\plexus-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:\SourceProject\zhenghe\oms_base\omsbase-rpcapi\target [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ omsbase-rpcapi --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 26 source files to D:\SourceProject\zhenghe\oms_base\omsbase-rpcapi\target\classes [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:\SourceProject\zhenghe\oms_base\omsbase-rpcapi\target\omsbase-rpcapi-1.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ omsbase-rpcapi --- [INFO] Installing D:\SourceProject\zhenghe\oms_base\omsbase-rpcapi\target\omsbase-rpcapi-1.0.1-SNAPSHOT.jar to D:\workspace\m3\com\emax\zhenghe\omsbase-rpcapi\1.0.1-SNAPSHOT\omsbase-rpcapi-1.0.1-SNAPSHOT.jar [INFO] Installing D:\SourceProject\zhenghe\oms_base\omsbase-rpcapi\pom.xml to D:\workspace\m3\com\emax\zhenghe\omsbase-rpcapi\1.0.1-SNAPSHOT\omsbase-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私服仓库截图:
附maven settings.xml里servers节点配置:
releases admin admin123 snapshots admin admin123