二、Maven服务端搭建
文章目录
一、Docker-compose安装Nexus
1、配置文件
准备:docker-compose.yml文件
version: '3'
services:
nexus:
image: sonatype/nexus3
container_name: nexus
restart: always
ports:
- "8081:8081"
volumes:
- ./nexus-data:/nexus-data3
2、启动
docker-compose up -d
3、查看admin登录密码
#进入docker
docker exec -it 658a79da77e6 /bin/bash
#查看密码
cat nexus-data/admin.password
二、配置nexus
1、添加外部Repositories
参考代理地址:
1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/
2、设置maven-public的优先级
maven拉去包的优先级:从上往下
3、设置添加用户
三、配置Maven的Client端setting.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\data\maven_repository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<!-- 这里设置方位私库的账号密码,id与 distributionManagement中id一致,distributionManagement中id一致一般配置在代码的pom中 -->
<servers>
<server>
<id>snapshots</id>
<username>wind</username>
<password>******</password>
</server>
<server>
<id>releases</id>
<username>wind</username>
<password>******</password>
</server>
</servers>
<!-- 这是从远程存储库下载依赖时使用的镜像列表 -->
<mirrors>
<mirror>
<id>maven-repository</id>
<mirrorOf>central</mirrorOf>
<name>maven-repository</name>
<url>http://192.168.27.128:8081/repository/maven-public/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>repo2</id>
<name>Mirror from Maven Repo2</name>
<url>http://repo2.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>profile-global</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>profile-global</activeProfile>
</activeProfiles>
</settings>
四、项目中的pom.xml配置
<!-- 指定推送jar到的仓库地址 -->
<distributionManagement>
<repository>
<id>releases</id>
<url>http://192.168.27.128:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.27.128:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
注意:当version指定以SNAPSHOTS结尾时,包就会推送到snapshots仓库,其它就会推送至release库中
五、参考资料
https://juejin.cn/post/6899671175304052750#heading-5