禁用重新部署时如何Maven发布多个配置文件项目 [英] How to maven release multiple profiles project when redeploys are disabled

查看:23
本文介绍了禁用重新部署时如何Maven发布多个配置文件项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: 当Nexus上禁用重新部署时,我应该如何发布具有2个独占配置文件的Maven项目?

示例(编辑): 我在pom.xml(P1和P2)中有一个带有2个配置文件的maven项目MyArtiact,它生成2个不同的EAR。每个配置文件将maven-ear-plugin配置为包括不同的模块,并自动生成application.xml。生成的构件是MyArtifact-1.0-P1.ear(2个WAR模块)和MyArtifact-1.0-P2.ear(3个WAR模块)。

问题1(重新部署到Nexus)

  1. 当我执行";mvn deploy -P P1";时,一切正常(war和pom部署到Nexus)
  2. 当我执行";mvn deploy -P P2";错误!Nexus抱怨重新部署pom.xml。

问题2(maven-Release-plugin)

当使用maven-release-plugin发布多个配置文件时,Maven会做很多事情(签出和标记CSM,更新POM版本,转向标记,提交到CSM,等等)。至少,必须为每个配置文件执行重新发布/重新标记既不高效也不实际。

推荐答案

是的!

考虑到使用配置文件,我正在使用maven<executions>功能:对我拥有的每个配置文件执行1次。每次执行都必须在不同的工作文件夹中生成资源。每个项目都有不同的分类器。部署Maven时,将找到3个构件(POM、EAR、EAR),并将它们部署到Nexus FINE。

下面是示例。如果您有任何问题,请告诉我:

<plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <executions>
            <execution>
                <!-- Disable default execution -->
                <id>default-ear</id>
                <phase>none</phase>
            </execution>
            <execution>
                <!-- Disable default execution -->
                <id>default-generate-application-xml</id>
                <phase>none</phase>
            </execution>
            <execution>
                <!-- execution for profile P1 -->
                <id>P1</id>
                <goals>
                    <goal>ear</goal>
                    <goal>generate-application-xml</goal>
                </goals>
                <configuration>
                    <!-- Different working directory for each profile (very important) -->
                    <workDirectory>target/P1</workDirectory>
                    <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                    <generateApplicationXml>true</generateApplicationXml>
                    <displayName>MyArtifactLibraryP1</displayName>
                    <!-- Different classifier for each profile (very important) -->
                    <classifier>P1</classifier>
                    <modules>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar1</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar2</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                    </modules>
                </configuration>
            </execution>
            <execution>
                <id>P2</id>
                <goals>
                    <goal>ear</goal>
                    <goal>generate-application-xml</goal>
                </goals>
                <configuration>
                    <workDirectory>target/P2</workDirectory>
                    <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                    <generateApplicationXml>true</generateApplicationXml>
                    <displayName>MyArtifactLibraryP2</displayName>
                    <classifier>P2</classifier>
                    <modules>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar1</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar2</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar3</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                    </modules>
                </configuration>
            </execution>
        </executions>
    </plugin>

这篇关于禁用重新部署时如何Maven发布多个配置文件项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆