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

时间:2022-02-04 19:54:50

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

<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>deployment</password>
</server>
</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

<profiles>
<profile>
<id>xxxx</id>
<properties>
<svn.name>username</svn.name>
<svn.pwd>password</svn.pwd>
</properties>
</profile>
</profiles>

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

<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xxx.xx.xxx</groupId>
<artifactId>xxxx</artifactId>
<version>0.3-SNAPSHOT</version>
</parent>
<groupId>xxx.xx.xxx</groupId>
<artifactId>parent</artifactId>
<name>parent</name>
<packaging>pom</packaging>
<scm>
<connection>scm:svn:https://192.168.1.88/svn/xxxx/trunk/parent</connection>
<url>https://192.168.1.88/svn/xxxx/trunk/parent</url>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>https://192.168.1.88/svn/xxxx/tags/</tagBase>
<username>${svn.name}</username>
<password>${svn.pwd}</password>
</configuration>
</plugin>
</plugins>
</build>
</project>




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

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