部署
1. Host
xxx.xxx.xxx.xxx:port
2. docker 搭建
- docker pull docker.io/sonatype/nexus
- docker run -d --restart always -p 8082:8081 --name nexus -v $PWD/data:/nexus-data sonatype/nexus
- 访问地址:http://xxx.xxx.xxx.xxx:port/nexus
- 默认用户名密码 admin/admin123
3. 代码打包上传私服
-
Maven pom 配置
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://${nexus.host}/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://${nexus.host}/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
-
maven 安装路径 conf/settings.xml servers 节点 添加
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server>
-
tips
pom 中的 id 与 settings 中的 id 节点名称相同
4. 发布部署
mvn clean && mvn -T 4C deploy -D maven.test.skip=true
5. 发布后访问地址
http://xxx.xxx.xxx.xxx:port/nexus/content/repositories/releases/
问题处理
1. 重复部署问题
- 错误信息
Failed to deploy artifacts: Could not transfer artifact | Failed to transfer file .pom with status code 400 -> [Help 1]
-
问题原因
nexus 默认配置不允许 重复 deploy
-
解决方案
->Releases
->configuration
-> Deployment Policy:Allow Redeploy