要部署快照版本构件至Nexus,你需要配置你项目POM的distributionManagement
部分的snapshotRepository
。Example 16.5, “为部署配置快照版本仓库”显示了快照版本部署仓库的样例,该snapshots
仓库配置的地址是http://localhost:8081/nexus/content/repositories/snapshots。
Example 16.5. 为部署配置快照版本仓库
<project> ... <distributionManagement> ... <snapshotRepository> <id>Snapshots</id> <name>Internal Snapshots</name> <url>http://localhost:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> ... </distributionManagement> ... </project>
你可以使用你Nexus安装的主机和端口来替换localhost:8081
。你的项目有了这个配置之后,你就可以通过执行mvn
deploy命令部署构件。如果你项目的版本是快照版本(如1.0-SNAPSHOT)Maven就会将其部署至snapshotRepository
:
$ mvn deploy
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] Sample Project
[INFO] ------------------------------------------------------------------------
[INFO] Building Sample Project
[INFO] task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [site:attach-descriptor]
[INFO] [install:install]
[INFO] Installing ~/svnw/sample/pom.xml to ~/.m2/repository/sample/sample\
/1.0-SNAPSHOT/sample-1.0-20080402.125302.pom
[INFO] [deploy:deploy]
altDeploymentRepository = null
[INFO] Retrieving previous build number from snapshots
Uploading: http://localhost:8081/nexus/content/repositories/releases/\
sample/sample/1.0-SNAPSHOT/sample-1.0-20080402.125302.pom
24K uploaded