本文最后更新于 2024年12月2日 晚上
准备存储卷
创建docker-compose.yml
创建文件: /usr/local/nexus/docker-compose.yml
, 内容如下:
1 2 3 4 5 6 7 8 9 10 11 12
| 文件内容: ```yml version: '3.1' services: nexus: restart: always image: sonatype/nexus3 container_name: nexus ports: - 8080:8080 volumes: - ./data:/nexus-data
|
赋予权限
1
| chmod 777 /usr/local/nexus/data
|
启动服务
代理第三方仓库
登录nexus
用户名、密码: admin/admin
代理第三方仓库
创建proxy类型仓库:
1 2 3 4 5
| http://mirrors.163.com/maven/repository/maven-public/ https://maven.aliyun.com/repository/public/ https://repo1.maven.org/maven2/ https://repo.spring.io/milestone/ https://repo.spring.io/snapshot/
|
代理仓库添加到public仓库
Maven settings.xml servers中添加认证信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <server> <id>nexus-public</id> <username>admin</username> <password>admin</password> </server> <server> <id>nexus-releases</id> <username>admin</username> <password>admin</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin</password> </server>
|
Maven settings.xml mirrors中配置只调用私服
1 2 3 4 5 6
| <mirror> <id>nexus-public</id> <mirrorOf>*</mirrorOf> <name>nexus-public</name> <url>http://192.168.0.112:8081/repository/maven-public/</url> </mirror>
|
Maven settings.xml profiles中配置连接信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <profile> <id>nexus</id> <repositories> <repository> <id>nexus-public</id> <name>Nexus Repository</name> <url>http://192.168.0.112:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-public</id> <name>Nexus Plugin Repository</name> <url>http://192.168.0.112:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> </pluginRepositories> </profile>
|
Maven settings.xml activeProfiles中启用配置
1
| <activeProfile>nexus</activeProfile>
|
项目pom.xml中配置私服地址
1 2 3 4 5 6 7 8 9 10 11 12
| <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://127.0.0.1:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
|
发布到仓库
上传第三方jar
1 2 3 4 5 6 7 8
| mvn deploy:deploy-file -DgroupId=com.aliyun.oss -DartifactId=aliyun-sdk-oss -Dversion=2.2.3 -Dpackaging=jar -Dfile=D:\aliyun-sdk-oss-2.2.3.jar -Durl=http://127.0.0.1:8081/repository/maven-3rd/ -DrepositoryId=nexus-releases
|