Release版本的项目应该发布到Releases仓库中,对应的,Snapshot版本应该发布到Snapshots仓库中。Maven根据pom.xml文件中版本号<version>节点的属性是否包含-SNAPSHOT,来判断该项目是否是snapshot版本。如果是snapshot版本,在执行mvn deploy部署命令时,maven会自动将项目发布到Snapshots仓库。要发布项目,首先需要将Releases仓库和Snapshots仓库的“Deployment Policy”设置为“Allow Redeploy”:
2、配置项目的部署仓库
在pom.xml中分别对Release版本和Snapshot版本配置部署仓库,其中id唯一,url分别对应私服中Releases和Snapshots仓库的Repository Path:
<uniqueVersion>表示是否为Snapshot版本分配一个包含时间戳的构建号,效果如下:
distributionManagement> <snapshotRepository> <id>user-snapshot</id> <name>User Porject Snapshot</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> <uniqueVersion>true</uniqueVersion> </snapshotRepository> <repository> <id>user-release</id> <name>User Porject Release</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> </distributionManagement>3、启用Deployment用户
Nexus默认有三个用户,其中Deployment用户用于部署项目:
Deployment用户默认密码为deployment123,右键菜单可修改或重置密码:
在settings.xml中分别为上面配置的部署仓库配置server,其中id需要分别对应上面的部署仓库id:
<servers> <server> <id>user-release</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>user-snapshot</id> <username>deployment</username> <password>deployment123</password> </server> … </servers>
右键pom.xml - Run As - 2 Maven build...
在Nexus仓库的Artifact Upload选项卡中,填写相关信息,可以手动的方式上传项目构件: