maven的settings.xml配置
<server>
<id>releases-id</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshot-id</id>
<username>admin</username>
<password>admin123</password>
</server>
-
id
自定义
id
,表示一个server
配置块,要保证唯一性,与distributionManagement
中的repository
元素的id
匹配 -
username/password
服务器认证需要的登录名和密码,可由私服的
Role
和User
等控制权限 -
privateKey/passphrase
(可选)两个元素指定了一个私钥的路径(默认是
/home/hudson/.ssh/id_dsa
)和一个密语。 -
filePermissions/directoryPermissions
(可选)权限对应了
linux
文件系统的权限,了解即可,如777.
项目pom文件配置
<scm>
<connection>
scm:svn:http://xxx/svn/code/xxx/${project.artifactId}/trunk
</connection>
<developerConnection>
scm:svn:http://xxx/svn/code/xxx/${project.artifactId}/trunk
</developerConnection>
<url>
http://xxx/svn/code/xxx/${project.artifactId}/trunk
</url>
</scm>
<distributionManagement>
<repository>
<id>releases-id</id>
<name>Release Repository</name>
<url>http://192.168.1.11:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot-id</id>
<name>Snapshot Repository</name>
<url>http://192.168.1.11:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
-
distributionManagement
配置发布到私服的分发仓库
-
repository
配置最终版本
releases
的仓库,deploy
时将项目的最终版本(x.x.x
)发布到releases
仓库 -
snapshotRepository
配置快照版本
snapshot
的仓库,deploy
时将项目的快照版本(x.x.x-SNAPSHOT
)发布到snapshots
仓库
注意
-
distributionManagement
中同时配置了releases
和snapshot
两个仓库,但是每次只会有一个生效!因为你pom
文件中的version
要么版本号带有-SNAPSHOT
,要么只有版本号的0.0.0
,因此maven
在deploy
的时候会根据version
后缀来匹配发布到哪个仓库中。 -
distributionManagement
只配置了releases
仓库,但是pom
的version
版本号带有-SNAPSHOT
,此时你deploy
的话,会报异常,如下异常 -
在
nexus
私服,选中Repositories
,选中Releases
的仓库,在Configuration
的Access Settings
有Deployment Policy
配置,默认是Disable Redeploy
,表示一个版本只允许上传一次,不允许覆盖,否则会报异常如下异常 -
异常
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project http-push: Failed to deploy artifacts: Could not transfer artifact com.p7.framework:http-push:jar:2.0.0 from/to releases (http://192.168.1.11:8081/nexus/content/repositories/releases): Failed to transfer file: http://192.168.1.11:8081/nexus/content/repositories/releases/com/p7/framework /http-push/2.0.0/http-push-2.0.0.jar. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]