首页 > 代码库 > maven nexus deploy方式以及相关注意事项

maven nexus deploy方式以及相关注意事项

以前公司都是配管负责管理jar的,现在没有专职配管了,得自己部署到deploy上供使用。总的来说,jar部署到nexus上有两种方式:

1、直接登录nexus控制台进行上传,如下:

技术分享

但是,某些仓库可能被设置了禁止控制台上传,如下:

技术分享

这种情况下,只能通过mvn:deploy进行部署了。

2、命令行方式上传。使用mvn:deploy部署前需要在settings.xml中配置server节点,指定仓库编号和用户名密码,如下所示:

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

这里的id应该需要和命令行中的repositoryId相同,否则会报401没有权限。

mvn deploy:deploy-file -DgroupId=com.ld.net.spider -DartifactId=com.ld.net.spider.ext -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -Dfile=C:\新建文件夹\com.ld.net.spider.ext-1.0.0-SNAPSHOT.jar -Durl=http://172.18.30.181:8081/nexus/content/repositories/snapshots -DrepositoryId=snapshots
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building com.ld.net.spider.parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ com.ld.net.spider.parent ---
Downloading: http://xxx:8081/nexus/content/repositories/snapshots/com/ld/net/spider/com.ld.net.spider.ext/maven-metadata.xml
Uploading: http://xxx:8081/nexus/content/repositories/snapshots/com/ld/net/spider/com.ld.net.spider.ext/1.0.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://xxx:8081/nexus/content/repositories/snapshots/com/ld/net/spider/com.ld.net.spider.ext/1.0.0-SNAPSHOT/maven-metadata.xml (788 B at 26.5 KB/sec)
Uploading: http://xxx:8081/nexus/content/repositories/snapshots/com/ld/net/spider/com.ld.net.spider.ext/maven-metadata.xml
Uploaded: http://xxx:8081/nexus/content/repositories/snapshots/com/ld/net/spider/com.ld.net.spider.ext/maven-metadata.xml (298 B at 10.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.028 s
[INFO] Finished at: 2016-09-27T18:32:32+08:00
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------

还需要一点注意的就是要部署的jar/pom不能位于本地仓库所在的目录:否则会出错,如下所示:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project com.ld.net.spider.parent: Cannot deploy artifact from the local repository: C:\apache-maven-3.3.9\repo\com\ld\net\spider\com.ld.net.spider.parent\1.0.0-SNAPSHOT\com.ld.net.spider.parent-1.0.0-SNAPSHOT.pom -> [Help 1]

注意上述事项后,应该是没有问题的。

maven nexus deploy方式以及相关注意事项