问题一

报错信息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project test-bill: Failed to deploy artifacts: Could not transfer artifact com.test.bill:test-bill:pom:1.0.9 from/to releases (http://maven-nexus.xxx.com/repository/maven-releases/): Failed to transfer file: http://maven-nexus.xxx.com/repository/maven-releases/com/test/bill/test-bill/1.0.9/test-bill-1.0.9.pom. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases. -> [Help 1]

解决

事先请确保nexus搭建正确,可以使用cmd执行带参数的mvn deploy命令成功上传一个jar来验证,cmd命令附上 xxx

mvn deploy:deploy-file -DgroupId=com.test -DartifactId=test -Dversion=1.2 -Dpackaging=jar -Dfile=E:\workspace\test-1.2.jar -Durl=http://maven-nexus.xxx.com/repository/maven-releases/ -DrepositoryId=releases

当然,该命令能成功执行的前提是本地安装的mvn目录的conf/settings.xml中配置有id为releases的server


浏览器登录nexus管理界面–>设置图标–>Repository–>Repositories–>maven-releases–>Hosted–>请选择‘Allow redeploy’策略,默认是disable策略,然后保存。 请注意,不同版本的nexus,进入的路径可能有细微区别


问题二

报错信息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://maven-nexus.xxx.com/nexus/content/repositories/releases/): Failed to transfer file: http://maven-nexus.xxx.com/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

解决

原来是没有配置认证。maven目录conf的setting.xml里,

    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
	  <server>
		  <id>snapshots</id>
		  <username>admin</username>
		  <password>admin123</password>
    </server>

用户名和密码都是nexus的。再次deploy即可。注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

<!-- 配置远程发布到私服,mvn deploy -->
	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>Nexus Release Repository</name>
			<url>http://maven-nexus.xxx.com/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>Nexus Snapshot Repository</name>
			<url>http://maven-nexus.xxx.com/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

如果这里不配置,会报错:

报错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter