需求:先有项目S在开发阶段,需要定期优化,然后有其他项目B需要依赖这个项目进行开发,由于项目S不稳定,经常更新版本,为了避免项目B频繁维护S项目的依赖关系,可将项目S设定为快照版本。
步骤:
1. 在项目S的配置文件pom.xml添加红色标识
<version>0.1.0-SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://10.110.1.41:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://10.110.1.41:8081/nexus/content/repositories/thirdparty/</url>
</repository>
</distributionManagement>
2. 在本地maven的setting.xml 文件夹添加
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
注意:pom.xml里的id和setting.xml的id要相同
3. 发布
mvn deploy -Dmaven.test.skip
4.项目B调用
pom.xml 添加远程仓库(私服)
<repository>
<id>public</id>
<url>http://10.110.1.41:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
pom.xml 添加依赖
<dependency>
<groupId>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>xxxx-SNAPSHOT</version>
</dependency>