maven-deploy-plugin 自动生成pom

1,018 阅读1分钟
  1. 通过版本号自动部署RELEASE或者SNAPSHOT仓库
  2. 通过generatePom=true设置自动生成pom.xml
  3. 解决maven-deploy-plugin 3.x 版本pom.xml 默认使用项目根目录的pom.xml的问题 以下是一个部署配置:
<plugin>  
    <groupId>org.codehaus.gmaven</groupId>  
    <artifactId>groovy-maven-plugin</artifactId>  
    <version>2.0</version>  
    <executions>  
        <execution>  
        <id>parse-repository</id>  
        <phase>validate</phase>  
        <goals>  
            <goal>execute</goal>  
        </goals>  
        <configuration>  
            <!-- 通过版本号是否包含SNAPSHOT自动发布到SNAPSHOT仓库 -->
            <source>  
            <![CDATA[  
            project.properties['deploy.repository.url'] = '${project.version}'.contains('SNAPSHOT') ? '${project.distributionManagement.snapshotRepository.url}' : '${project.distributionManagement.repository.url}'  
            project.properties['deploy.repository.id'] = '${project.version}'.contains('SNAPSHOT') ? '${project.distributionManagement.snapshotRepository.id}' : '${project.distributionManagement.repository.id}'  
            ]]>  
            </source>  
        </configuration>  
        </execution>  
    </executions>  
</plugin>
<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-install-plugin</artifactId>  
    <version>2.4</version>  
    <executions>  
        <execution>  
            <id>default-install</id>  
            <phase>install</phase>  
            <goals>  
                <goal>install</goal>  
            </goals> 
            <configuration>  
                <!-- skip默认install动作 -->  
                <skip>true</skip>  
            </configuration>  
        </execution>  
        <execution>  
            <id>install-file</id>  
            <phase>install</phase>  
            <goals>  
                <goal>install-file</goal>  
            </goals>  
            <configuration>  
                <packaging>jar</packaging>  
                <generatePom>true</generatePom>  
                <groupId>${project.groupId}</groupId>  
                <artifactId>${project.artifactId}</artifactId>  
                <version>${project.version}</version>  
                <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>  
                <sources>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</sources>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>
<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-deploy-plugin</artifactId>  
    <version>2.8.2</version>
    <executions>  
        <execution>  
            <id>default-deploy</id>  
            <phase>deploy</phase>  
            <goals>  
                <goal>deploy</goal>  
            </goals>  
            <configuration>
                <!-- skip默认deploy动作 -->
                <skip>true</skip>  
            </configuration>  
        </execution>  
        <execution>  
            <id>deploy-file</id>  
            <phase>deploy</phase>  
            <goals>  
                <goal>deploy-file</goal>  
            </goals>  
            <configuration>  
                <packaging>jar</packaging>  
                <!-- 生成新的pom -->
                <generatePom>true</generatePom>
                <!-- maven-deploy-plugin 2.x版本不需要这个配置,3.x版本如果不配置pomFile,会使用项目根目录的pom.xml,所以如果是3.x版本这里可以指定pomFile为install到本地生成的pom。
                <pomFile>${settings.localRepository}/com/wanmei/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}.pom</pomFile>
                -->
                <groupId>${project.groupId}</groupId>  
                <artifactId>${project.artifactId}</artifactId>  
                <version>${project.version}</version>  
                <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>  
                <sources>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</sources>  
                <repositoryId>${deploy.repository.id}</repositoryId>  
                <url>${deploy.repository.url}</url>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>