(一) SpringBoot配置Maven发布至Nexus私服
- Nexus默认会带有四常用个仓库,maven-central、maven-public、maven-releases、maven-snapshots
- maven-central类型是proxy代理类型,地址是指向maven中央仓库地址https://repo1.maven.org/maven2/
- maven-releases、maven-snapshots类型是hosted宿主类型,即代表是上线的稳定版本依赖和开发阶段的快照版本
- maven-public类型是group组类型,里面是maven-releases、maven-snapshots、maven-central。即当指向maven-public时会去组下面的三个仓库去寻找包依赖
首先将我的Spring-Cloud工程里面的包依赖指向我搭建的nexus私服。首先修改maven的settings.xml。配置私服镜像
- servers配置虚拟机搭建的nexus私服默认的账号密码
<servers>
<server>
<id>mac-ubuntu</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
- mirrors配置nexus私服镜像指向maven-public组
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://127.0.0.1:8081/repository/maven-public/</url>
</mirror>
</mirrors>
- 配置profile,由于我们镜像指向了maven-public仓库组,这里配置一个假地址
<profiles>
<profile>
<id>mac-nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
- 配置activeProfiles,id是上面profile定义的id
<activeProfiles>
<activeProfile>mac-nexus</activeProfile>
</activeProfiles>
- 配置我的工程SpringCloud-Project中的parent-maven父类pom.xml,Github仓库。将配置打包至虚拟机nexus私服 id必须和maven setting.xml中server配置的ID一样(即mac-ubuntu),否则会找不到nexus私服报错401
<distributionManagement>
<repository>
<id>mac-ubuntu</id>
<name>Releases</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>mac-ubuntu</id>
<name>Snapshot</name>
<url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
- 执行mvn deploy打包项目,会看到依赖包会上传至maven-snapshots仓库。因为我pom.xml定义的是快照版本
(二) 配置Spring Milestones
由于我的SpringCloud-Project用的是springcloud。pom.xml文件中会使用spring-milestones这个仓库。这样我也需要将其配置至nexus私服
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
- 在nexus新建一个代理类型的仓库spring-m,地址指向https://repo.spring.io/milestone
- 在nexus新建一个group组类型的仓库spring-milestone,将上面新建好的spring-m仓库添加进来
[外链图片转存中…(img-VtS3oS8M-1669989739056)]
- 然后和上面配置maven-public一样,在maven的settings.xml中配置spring-milestone
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://127.0.0.1:8081/repository/spring-milestones/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>spring-milestones</id>
<repositories>
<repository>
<id>spring-milestones</id>
<url>https://spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<url>https://spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>spring-milestones</activeProfile>
</activeProfiles>