maven release插件将一版本发布到仓库中时Return code is: 401, ReasonPhrase:Unauthorized

时间:2023-03-10 02:44:31
maven release插件将一版本发布到仓库中时Return code is: 401, ReasonPhrase:Unauthorized

需要在maven的setting.xml中配置servers.server节点,其值为nexus的对应的repository的id以及用户名及密码

  1. <servers>
  2. <server>
  3. <id>releases</id>
  4. <username>admin</username>
  5. <password>admin</password>
  6. </server>
  7. <server>
  8. <id>snapshots</id>
  9. <username>deployment</username>
  10. <password>deployment</password>
  11. </server>
  12. </servers>

mvn release:prepare -Pxxxx 将用setting.xml中定义的profile为我们提交,打tag,升级pom,再提交的一连串动作(但不要忘了setting.xml的profile定义及pom.xm中定义好maven-release-plugin的tagBase,username,password以及每个模块的scm信息)

maven conf/setting.xml

  1. <profiles>
  2. <profile>
  3. <id>xxxx</id>
  4. <properties>
  5. <svn.name>username</svn.name>
  6. <svn.pwd>password</svn.pwd>
  7. </properties>
  8. </profile>
  9. </profiles>

项目 pom.xml (让子模块都继承自另一个模块,类型为pom,假定名称为parent)

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <parent>
  4. <groupId>xxx.xx.xxx</groupId>
  5. <artifactId>xxxx</artifactId>
  6. <version>0.3-SNAPSHOT</version>
  7. </parent>
  8. <groupId><u><span style="color:#0066cc;">xxx.xx.xxx</span></u></groupId>
  9. <artifactId>parent</artifactId>
  10. <name>parent</name>
  11. <packaging>pom</packaging>
  12. <scm>
  13. <connection>scm:svn:https://192.168.1.88/svn/xxxx/trunk/parent</connection>
  14. <url>https://192.168.1.88/svn/xxxx/trunk/parent</url>
  15. </scm>
  16. <build>
  17. <plugins>
  18. <plugin>
  19. <groupId>org.apache.maven.plugins</groupId>
  20. <artifactId>maven-release-plugin</artifactId>
  21. <configuration>
  22. <tagBase>https://192.168.1.88/svn/xxxx/tags/</tagBase>
  23. <username>${svn.name}</username>
  24. <password>${svn.pwd}</password>
  25. </configuration>
  26. </plugin>
  27. </plugins>
  28. </build>
  29. </project>
maven release插件将一版本发布到仓库中时Return code is: 401, ReasonPhrase:Unauthorized

这样mvn release:perform时maven-release-plugin会自动帮我们签出刚才打的tag,然后打包,分发到远程Maven仓库中(nexus).

注意:如果要把快照版本也发布到存储库,需要在trunk中执行mvn deploy,并且一定要配置snapshotRepository