部署插件具有所有必要的功能:
您可以在其配置中设置 G/A/V 坐标,并将任意数量的附加工件部署到您想要的任何坐标。但是,它不会自动部署到您distributionManagement
部分中给出的存储库 URL。
为了避免重复,我最后求助于 GMaven 插件,用它来检查项目版本(是否-SNAPSHOT
以distributionManagement
.
这是两个插件的配置:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>choose-target-repository</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
if (project.version.endsWith("-SNAPSHOT")){
project.properties.targetrepository = project.distributionManagement.snapshotRepository.url;
}
else {
project.properties.targetrepository = project.distributionManagement.repository.url;
}
</source>
</configuration>
</execution>
</executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-myclassifier</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>
${project.build.directory}/${project.artifactId}-${project.version}-myclassifier.zip
</file>
<groupId>${project.groupId}</groupId>
<artifactId>myprojectname</artifactId>
<version>${project.version}</version>
<classifier>myclassifier</classifier>
<repositoryId>nexus</repositoryId>
<url>http://url-to-nexus</url>
</configuration>
</execution>
</executions>
</plugin>