目标
公共包从阿里maven仓库获取
私有包由nexus私服管理
安装
- 安装JDK8
- 安装maven3
- 安装nexus
下载
https://help.sonatype.com/repomanager3/download?_ga=2.981497.977242279.1553142814-913108894.1552909009
解压
运行,以windows为例
%nexus_home%\nexus-3.15.2-01\bin\nexus.exe /run
访问
http://localhost:8081/
配置
- 移除public group库中的maven-central成员
使用默认账号admin/admin123登录
将maven-central从maven-public的成员列表中移除 - 设置本地的settings.xml
1)在profiles中配置私服
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus-local</id>
<url>http://localhost:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
2)默认激活dev
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
3)配置mirror
<mirror>
<id>nexus-aliyun</id>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>*,!nexus-local</mirrorOf>
</mirror>
- 发布包和源码到私服
1)settings.xml设置发布所用的用户名&密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
2)项目pom.xml中设置发布地址
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshot</name>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
3)项目pom.xml中新增打包源码插件
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
4)发布
5.结果
参考资料
[1]. maven nexus3.13 安装 —Windows服务器安装过程和基本使用
[2]. Maven系列二setting.xml 配置详解