Maven私服Nexus的搭建和使用(Mac)
阿新 • • 發佈:2019-02-10
1.下載對應的安裝包
https://www.sonatype.com/oss-thank-you-mac-tgz 注意:目前的版本有2.X 和 3.X ,2.X的支援對Maven更友好一點,3.X的支援範圍更廣,支援ruby和docker。如果單純的maven私服,建議使用2.x 2.解壓安裝包,並進入對應的bin目錄下啟動nexus ./nexus start 注意:3.X要求JDK的版本在1.8以上 3.訪問地址,3.x預設是127.0.0.1:8081 2.x預設是127.0.0.1:8081/nexus ,預設的登陸賬戶密碼為admin/admin123 修改埠或者密碼,在etc下的nexus-default.properties 4.簡單介紹一下Repository Repository的type屬性有:proxy,hosted,group三種。 proxy:即你可以設定代理,設定了代理之後,在你的nexus中找不到的依賴就會去配置的代理的地址中找 hosted:你可以上傳你自己的專案到這裡面 group:它可以包含前面兩個,是一個聚合體。一般用來給客戶一個訪問nexus的統一地址。 簡單的說,就是你可以上傳私有的專案到hosted,以及配置proxy以獲取第三方的依賴(比如可以配置中央倉庫的地址)。前面兩個都弄好了之後,在通過group聚合給客戶提供統一的訪問地址 5.如何上傳jar包 先設定settings.xml,這裡主要是配置使用者名稱和密碼,注意這裡的id要和respositoryId對應 <servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers> 控制檯 mvn deploy:deploy-file -DgroupId=ebay -DartifactId=ebay -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=/Users/yuliangliang/ebay-0.0.1-SNAPSHOT.jar -Durl=http://localhost:8081/repository/maven-snapshots/ -DrepositoryId=nexus 效果如下 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Downloading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.jar Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.jar (34194 KB at 22218.2 KB/sec) Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.pom Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.pom (390 B at 5.5 KB/sec) Downloading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml (758 B at 10.4 KB/sec) Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml (268 B at 4.0 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.567 s [INFO] Finished at: 2018-01-02T22:50:38+08:00 [INFO] Final Memory: 8M/155M [INFO] ------------------------------------------------------------------------ 也可以同步本地倉庫到私服上去
6.專案中的使用,這樣就能在專案中引用了,具體的引用可以在pom中配置,也可以在maven的settings.xml檔案中修改 <mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles> 7.上傳專案到私服上去 先設定settings.xml,配置servers,見步驟5 專案的pom檔案新增如下程式碼 <distributionManagement>
<repository>
<id>release</id>
<name>Release Repository</name>
<url>http://ip/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot</id>
<name>Snapshot Repository</name>
<url>http://ip/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
執行deploy -e即可
https://www.sonatype.com/oss-thank-you-mac-tgz 注意:目前的版本有2.X 和 3.X ,2.X的支援對Maven更友好一點,3.X的支援範圍更廣,支援ruby和docker。如果單純的maven私服,建議使用2.x 2.解壓安裝包,並進入對應的bin目錄下啟動nexus ./nexus start 注意:3.X要求JDK的版本在1.8以上 3.訪問地址,3.x預設是127.0.0.1:8081 2.x預設是127.0.0.1:8081/nexus ,預設的登陸賬戶密碼為admin/admin123 修改埠或者密碼,在etc下的nexus-default.properties 4.簡單介紹一下Repository Repository的type屬性有:proxy,hosted,group三種。 proxy:即你可以設定代理,設定了代理之後,在你的nexus中找不到的依賴就會去配置的代理的地址中找 hosted:你可以上傳你自己的專案到這裡面 group:它可以包含前面兩個,是一個聚合體。一般用來給客戶一個訪問nexus的統一地址。 簡單的說,就是你可以上傳私有的專案到hosted,以及配置proxy以獲取第三方的依賴(比如可以配置中央倉庫的地址)。前面兩個都弄好了之後,在通過group聚合給客戶提供統一的訪問地址 5.如何上傳jar包 先設定settings.xml,這裡主要是配置使用者名稱和密碼,注意這裡的id要和respositoryId對應 <servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers> 控制檯 mvn deploy:deploy-file -DgroupId=ebay -DartifactId=ebay -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=/Users/yuliangliang/ebay-0.0.1-SNAPSHOT.jar -Durl=http://localhost:8081/repository/maven-snapshots/ -DrepositoryId=nexus 效果如下 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Downloading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.jar Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.jar (34194 KB at 22218.2 KB/sec) Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.pom Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/ebay-0.0.1-20180102.145036-1.pom (390 B at 5.5 KB/sec) Downloading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/0.0.1-SNAPSHOT/maven-metadata.xml (758 B at 10.4 KB/sec) Uploading: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml Uploaded: http://localhost:8081/repository/maven-snapshots/ebay/ebay/maven-metadata.xml (268 B at 4.0 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.567 s [INFO] Finished at: 2018-01-02T22:50:38+08:00 [INFO] Final Memory: 8M/155M [INFO] ------------------------------------------------------------------------ 也可以同步本地倉庫到私服上去
6.專案中的使用,這樣就能在專案中引用了,具體的引用可以在pom中配置,也可以在maven的settings.xml檔案中修改 <mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://127.0.0.1:8082/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles> 7.上傳專案到私服上去 先設定settings.xml,配置servers,見步驟5 專案的pom檔案新增如下程式碼 <distributionManagement>
<repository>
<id>release</id>
<name>Release Repository</name>
<url>http://ip/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot</id>
<name>Snapshot Repository</name>
<url>http://ip/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
執行deploy -e即可