采用Nexus搭建Maven私服
1.采用docker安装
1.创建数据目录
挂载的目录:
/usr/local/springcloud_1113/nexus3/nexus-data
2.查询并拉取镜像
docker search nexus3
docker pull sonatype/nexus3
3.查看拉取的镜像
docker images
4.创建docker容器:可能出现启动后停止,可能的原因就是服务器的内存是不足的
docker run -id --privileged=true --name=nexus3 --restart=always -p 58081:8081 -v /usr/local/springcloud_1113/nexus3/nexus-data:/var/nexus-data sonatype/nexus3
5.查看日志
docker logs -f nexus3
2.访问
1.访问地址:http://192.168.101.131:58081/
2.查看默认的密码
docker exec -it 78fa7a779952 bash
bash-4.4$ more nexus-data/admin.password
6fe68b57-20b4-4242-b311-8df8210f1b2b
3.仓库分为发行版和快照版。根据的是版本的后缀进行判断的。不写的话就是默认的发行版。
3.设置阿里云代理
https://maven.aliyun.com/repository/central
https://maven.aliyun.com/repository/public
4.本地settings.xml设置
<localRepository>D:xxx\apache-maven-3.6.3\repository</localRepository>
<mirrors>
<!-- Maven私服配置 -->
<mirror>
<id>maven-public</id>
<name>maven-public</name>
<url>http://192.168.101.131:58081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
<!--阿里云maven库-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
需要和pom中的保持一致
<servers>
<!-- Nexus私服发布的用户名密码 -->
<server>
<id>maven-public</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<profiles>
<!-- 配置jdk版本 -->
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<!-- Nexus私服配置 -->
<repositories>
<repository>
<id>maven-public</id>
<url>http://192.168.101.131:58081/repository/maven-public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven-releases</id>
<url>http://192.168.101.131:58081/repository/maven-releases/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<!-- 阿里云配置: 提高国内的jar包下载速度 -->
<profile>
<id>ali</id>
<repositories>
<repository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 激活配置 -->
<activeProfiles>
<activeProfile>jdk1.8</activeProfile>
<activeProfile>ali</activeProfile>
</activeProfiles>
5.本地项目创建-并上传
pom中加入
<!-- 配置私服仓库-->
<distributionManagement>
<!-- 发布版本仓库 -->
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.101.131:58081/repository/maven-releases/</url>
</repository>
<!-- 快照版本仓库 -->
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.101.131:58081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
编写一点测试代码。代码的打包方式需要时jar的方式。
上传完成
查看
6.下载设置
pom中加入下面的内容
<repositories>
<repository>
<id>maven-releases</id>
<url>http://192.168.101.131:58081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://192.168.101.131:58081/repository/maven-snapshots/</url>
</repository>
</repositories>
导入依赖
<dependency>
<groupId>com.lxz.test</groupId>
<artifactId>demo1116</artifactId>
<version>1.0.0</version>
</dependency>
mvn clean package -DskipTests -e -U -X
7.测试
@Test
void contextLoads() {
CommonUtils.SayHello("你好!");
}