1.Nexus环境搭建
1.1 下载镜像
#1.下载一个nexus3的镜像
docker pull sonatype/nexus3
1.2 运行Nexus容器
#2.将容器内部/var/nexus-data挂载到主机/root/nexus-data目录
docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3
关闭防火墙,访问http://ip:8081
进入容器获取初始密码:
docker exec -it nexus /bash/bin
vi /nexus-data/admin.password
默认登录账号:admin/获取的密码,并修改密码
1.3 创建私服账户和仓库
创建账户(wmh/wmh),并赋予权限
创建maven2(hosted),私人仓库:wmh-release
修改maven-central仓库中心仓库地址为阿里云仓库
http://maven.aliyun.com/nexus/content/groups/public/
1.4 修改本地maven,settings.xml文件
<mirrors>
<mirror>
<id>wmh</id>
<name>Repository in My Orgnization</name>
<url>http://192.168.75.128:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<servers>
<server>
<id>wmh</id>
<username>wmh</username>
<password>wmh</password>
</server>
</servers>
<profiles>
<repository>
<id>wmh</id>
<url>http://192.168.75.128:8081/repository/maven-snapshots/</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
</profiles>
1.5 打包本地jar包到私服
添加pom依赖:
<!--注意限定版本一定为RELEASE,因为上传的对应仓库的存储类型为RELEASE -->
<!--指定仓库地址 -->
<distributionManagement>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>wmh</id>
<url>http://192.168.75.128:8081/repository/wmh-release/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<!--发布代码Jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<!--发布源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
执行命令:
mvn deploy