下面我们通过一个实例来详细介绍如何使用 Maven 部署构件到 Nexus 宿主仓库。
<project> ... <distributionManagement> <repository> <id>bianchengbang_Release_hosted</id> <url>http://localhost:8082/nexus/content/repositories/bianchengbang_Release_hosted/</url> </repository> <snapshotRepository> <id>bianchengbang_Snapshot_hosted</id> <url>http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hosted/</url> </snapshotRepository> </distributionManagement> </project>
<settings> ... <servers> <server> <id>bianchengbang_Release_hosted</id> <username>admin</username> <password>admin123</password> </server> <server> <id>bianchengbang_Snapshot_hosted</id> <username>admin</username> <password>admin123</password> </server> </servers> </settings>
mvn clean deploy
[INFO] Scanning for projects... [INFO] [INFO] ---------------< net.biancheng.www:test-upload-snapshot >--------------- [INFO] Building test-upload-snapshot 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-upload-snapshot --- [INFO] Deleting D:\eclipse workSpace 3\test-upload-snapshot\target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-upload-snapshot --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-upload-snapshot --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-upload-snapshot --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-upload-snapshot --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-upload-snapshot --- [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-upload-snapshot --- [INFO] Building jar: D:\eclipse workSpace 3\test-upload-snapshot\target\test-upload-snapshot-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ test-upload-snapshot --- [INFO] Installing D:\eclipse workSpace 3\test-upload-snapshot\target\test-upload-snapshot-0.0.1-SNAPSHOT.jar to D:\myRep ository\repository\net\biancheng\www\test-upload-snapshot\0.0.1-SNAPSHOT\test-upload-snapshot-0.0.1-SNAPSHOT.jar [INFO] Installing D:\eclipse workSpace 3\test-upload-snapshot\pom.xml to D:\myRepository\repository\net\biancheng\www\te st-upload-snapshot\0.0.1-SNAPSHOT\test-upload-snapshot-0.0.1-SNAPSHOT.pom [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ test-upload-snapshot --- Downloading from bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_ hosted/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/maven-metadata.xml Downloaded from bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_h osted/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/maven-metadata.xml (787 B at 9.2 kB/s) Uploading to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_host ed/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/test-upload-snapshot-0.0.1-20210322.030343-5.jar Uploaded to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hoste d/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/test-upload-snapshot-0.0.1-20210322.030343-5.jar (2.1 kB at 28 k B/s) Uploading to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_host ed/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/test-upload-snapshot-0.0.1-20210322.030343-5.pom Uploaded to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hoste d/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/test-upload-snapshot-0.0.1-20210322.030343-5.pom (2.4 kB at 36 k B/s) Downloading from bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_ hosted/net/biancheng/www/test-upload-snapshot/maven-metadata.xml Downloaded from bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_h osted/net/biancheng/www/test-upload-snapshot/maven-metadata.xml (297 B at 11 kB/s) Uploading to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_host ed/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/maven-metadata.xml Uploaded to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hoste d/net/biancheng/www/test-upload-snapshot/0.0.1-SNAPSHOT/maven-metadata.xml (787 B at 14 kB/s) Uploading to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_host ed/net/biancheng/www/test-upload-snapshot/maven-metadata.xml Uploaded to bianchengbang_Snapshot_hosted: http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hoste d/net/biancheng/www/test-upload-snapshot/maven-metadata.xml (297 B at 5.2 kB/s) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.342 s [INFO] Finished at: 2021-03-22T11:03:44+08:00 [INFO] ------------------------------------------------------------------------
在 Nexus 界面的仓库列表选中 bianchengbang_Snapshot_hosted 宿主仓库,在下方的 Browse Index 选项卡中,可以看到 test-upload-snapshot 构件已经被部署到该仓库中,如图 1 所示。
图1:使用 Maven 部署构件到 Nexus
mvn clean package
图2:Maven 打包生成 jar 文件
若该构件是通过 Maven 构建产生的,那么可以在 GAV Definition 下拉列表中,选择 From POM,然后指定该构件所属项目的 pom.xml,Nexus 会自动从 pom.xml 中获取构件的坐标。最后点击页面最下方的 Upload Artifact(s) 按钮,将构件上传到仓库中,如图 3 所示。
图3:Nexus 手动上传构件
图4:Nexus 第三方构件手动上传
图5:第三方构件手动上传到Nexus
本文链接:http://task.lmcjl.com/news/13905.html