项目中 Maven 私服 Nexus 的使用
配置认证信息
在Maven的 settings.xml 中的servers节点下添加Nexus认证信息
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
id:配置的服务id
username:Nexus私服用户名
password:Nexus私服登录密码
Snapshots(快照版)与Releases(发行版)
- Snapshot与Release版本定义如下:
Release: 1.0.0/1.0.0-RELEASE
Snapshot: 1.0.0-SNAPSHOT
- 在项目pom.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本,没有SNAPSHOT标识的都会发布为RELEASE版本。
- SNAPSHOT版本会自动加一个时间作为标识,如:1.0.0-SNAPSHOT发布后变成 1.0.0-SNAPSHOT-20190920.191919-1.jar
配置自动化部署
项目 pom.xml 文件配置以下内容
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.1.128:8080/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.1.128:8080/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
注意事项:
- ID名称必须要与settings.xml中server配置的ID名称保持一致
- 项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository,否则发布到Nexus Release Repository,并根据ID去匹配授权账号
部署到仓库
mvn deploy
第三方JAR包的上传
Nexus 3.0 不支持页面上传,可使用maven命令:
# mysql-connector-java-8.0.17.jar 为例
mvn deploy:deploy-file
-DgroupId=mysql
-DartifactId=mysql-connector-java
-Dversion=8.0.17
-Dpackaging=jar
-Dfile=D:\mysql-connector-java-8.0.17.jar
-Durl=http://192.168.1.128:8081/repository/maven-3f/
-DrepositoryId=nexus-releases
注意事项:
- 上面命令需要作为一行执行,不能有换行
- maven-3f,单独创建的第三方jar包管理仓库,便于管理维护
- -DrepositoryId=nexus-releases,对应得是 settings.xml 中配置服务的ID名称
配置代理仓库
项目 pom.xml 文件配置以下内容
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repository</name>
<url>https://192.168.1.128:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Nexus Plugin Repository</name>
<url>http://192.168.1.128:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>