maven发布jar包到nexus

时间:2021-11-28 19:04:47

自定义的jar包提交到nexus的私服中,直接通过maven命令提交。

mvn clean source:jar deploy -X -DskipTests=true

参数解释:

  • clean 清空上次编译结果
  • deploy 发布到情况
  • source:jar 同步发布源码
  • -X debug级别日志输出
  • -DskipTests=true 跳过单元测试

执行的过程中出现一个错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project io: Failed to deploy artifacts: Could not transfer artifact cn.infisa:io:jar:1.0.2-RELEASE from/to releases (http://192.168.1.62:8081/nexus/content/repositories/releases/): Failed to transfer file: http://192.168.1.62:8081/nexus/content/repositories/releases/cn/infisa/io/1.0.2-RELEASE/io-1.0.2-RELEASE.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]

原因: 本地用户提交releases或者snapshots里面,需要配置对应的权限,而且需要在settings.xml中配置。

<server>
    <username>username</username>
    <password>password</password>
    <id>releases</id>
</server>

再次提交,成功通过。