搭建maven私服
阿新 • • 發佈:2021-01-24
搭建maven私服環境
Nexus 是 Maven 倉庫管理器, 通過 nexus 可以搭建 maven 倉庫,同時 nexus 還提供強大的倉庫管理功能,構件搜尋功能等
- nexus.bat install
- nexus.bat uninstall
- nexus.bat start
登入
http://localhost:8081/nexus/
nexus 的倉庫有 4 種類型:
- hosted,宿主倉庫, 部署自己的 jar 到這個型別的倉庫,包括 releases 和 snapshot 兩部 分, Releases 公司內部發布版本倉庫、 Snapshots 公司內部測試版本倉庫
- proxy,代理倉庫, 用於代理遠端的公共倉庫,如 maven 中央倉庫,使用者連線私服,私 服自動去中央倉庫下載 jar 包或者外掛。
- group,倉庫組,用來合併多個 hosted/proxy 倉庫,通常我們配置自己的 maven 連線倉 庫組。
- virtual(虛擬):相容 Maven1 版本的 jar 或者外掛
將專案釋出到私服
修改 settings.xml檔案
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</ password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
releases: 連線釋出版本專案倉庫
snapshots: 連線測試版本專案倉庫
配置專案 pom.xml
<distributionManagement>
<repository>
< id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
測試
、 首先啟動 nexus
2、 對工程執行 deploy 命令
從私服下載 jar 包
<profile>
<!--profile 的 id-->
<id>dev</id>
<repositories>
<repository>
<!--倉庫 id, repositories 可以配置多個倉庫,保證 id 不重複-->
<id>nexus</id>
<!--倉庫地址,即 nexus 倉庫組的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下載 releases 構件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下載 snapshots 構件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 外掛倉庫, maven 的執行依賴外掛,也需要從私服下載外掛 -->
<pluginRepository>
<!-- 外掛倉庫的 id 不允許重複,如果重複後邊配置會覆蓋前邊 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>