【问题标题】:Using maven release plugin on multi-module project在多模块项目上使用 maven 发布插件
【发布时间】:2020-05-27 22:11:26
【问题描述】:

我有一个包含两个模块的多模块项目:war 和 ear 模块。我正在尝试使用 Maven 发布插件来管理发布。

到目前为止我的配置...

父pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>Test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>Test-WAR</module>
        <module>Test-EAR</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <!-- some other properties -->
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- some dependencies -->
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>nexus-snapshots</id>
            <name>nexus</name>
            <url>http://nexus.example.com:8081/repository/maven-snapshots</url>
        </repository>
        <repository>
            <id>nexus-releases</id>
            <name>nexus</name>
            <url>http://nexus.example.com:8081/repository/maven-releases</url>
        </repository>
    </repositories>

    <distributionManagement>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>nexus</name>
            <url>http://nexus.example.com:8081/repository/maven-snapshots</url>
        </snapshotRepository>
        <repository>
            <id>nexus-releases</id>
            <name>nexus</name>
            <url>http://nexus.example.com:8081/repository/maven-releases</url>
        </repository>
    </distributionManagement>

    <scm>
        <connection>scm:git:http://gitlab.example.com/test/Test.git</connection>
        <developerConnection>scm:git:http://gitlab.example.com/test/Test.git</developerConnection>
        <url>http://gitlab.example.com/test/Test</url>
    </scm>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <releaseProfiles>release</releaseProfiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.zeroturnaround</groupId>
                <artifactId>jrebel-maven-plugin</artifactId>
                <version>1.1.8</version>
                <executions>
                    <execution>
                        <id>generate-rebel-xml</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <executions>
                    <execution>
                        <id>deploy-parent</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

战争模块 pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example</groupId>
        <artifactId>Test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>Test-WAR</artifactId>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- some dependencies -->
    </dependencies>

    <profiles>
        <!-- dev -->
        <profile>
            <id>dev</id>
            <properties>
                <CREATE_EJB_STUBS_SCRIPT_FILE>createEJBStubs.bat</CREATE_EJB_STUBS_SCRIPT_FILE>
                <APP_CLASSES_DIR>${basedir}/target/classes</APP_CLASSES_DIR>
                <EJB_LOCATION>src/test/resources/build/${project.parent.artifactId}.jar</EJB_LOCATION>
                <EJB_CLIENT_LOCATION>src/test/resources/build/${project.parent.artifactId}-${project.parent.version}.jar</EJB_CLIENT_LOCATION>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                        <executions>
                            <execution>
                                <id>deploy-ejb-client</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-file</goal>
                                </goals>
                                <configuration>
                                    <repositoryId>nexus-snapshots</repositoryId>
                                    <file>${EJB_CLIENT_LOCATION}</file>
                                    <url>http://nexus.example.com:8081/repository/maven-snapshots</url>
                                    <groupId>${project.parent.groupId}</groupId>
                                    <artifactId>${project.parent.artifactId}-EJB-CLIENT</artifactId>
                                    <version>${project.parent.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deploy-ejb</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-file</goal>
                                </goals>
                                <configuration>
                                    <repositoryId>nexus-snapshots</repositoryId>
                                    <file>${EJB_LOCATION}</file>
                                    <url>http://nexus.example.com:8081/repository/maven-snapshots</url>
                                    <groupId>${project.parent.groupId}</groupId>
                                    <artifactId>${project.parent.artifactId}-EJB</artifactId>
                                    <version>${project.parent.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- release -->
        <profile>
            <id>release</id>
            <properties>
                <CREATE_EJB_STUBS_SCRIPT_FILE>createEJBStubs.bat</CREATE_EJB_STUBS_SCRIPT_FILE>
                <APP_CLASSES_DIR>../../../Test-WAR/target/classes</APP_CLASSES_DIR>
                <EJB_LOCATION>../../../Test-WAR/src/test/resources/build/${project.parent.artifactId}.jar</EJB_LOCATION>
                <EJB_CLIENT_LOCATION>../../../Test-WAR/src/test/resources/build/${project.parent.artifactId}-${project.parent.version}.jar</EJB_CLIENT_LOCATION>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>ant-build</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <property name="server.dir" value="${SERVER_DIR}" />
                                        <property name="createEjbStubsScriptFile" value="${CREATE_EJB_STUBS_SCRIPT_FILE}" />
                                        <property name="appClassesDir" value="${APP_CLASSES_DIR}" />
                                        <property name="author" value="${project.organization.name}" />
                                        <property name="maven.root" value="${project.parent.artifactId}" />
                                        <property name="maven.war.artifactId" value="${project.artifactId}" />
                                        <property name="maven.war.version" value="${project.parent.version}" />
                                        <ant antfile="${basedir}/src/test/resources/ant/build.xml">
                                            <target name="run" />
                                        </ant>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                        <executions>
                            <execution>
                                <id>deploy-ejb-client</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-file</goal>
                                </goals>
                                <configuration>
                                    <repositoryId>nexus-releases</repositoryId>
                                    <file>${EJB_CLIENT_LOCATION}</file>
                                    <url>http://nexus.example.com:8081/repository/maven-releases</url>
                                    <groupId>${project.parent.groupId}</groupId>
                                    <artifactId>${project.parent.artifactId}-EJB-CLIENT</artifactId>
                                    <version>${project.parent.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deploy-ejb</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-file</goal>
                                </goals>
                                <configuration>
                                    <repositoryId>nexus-releases</repositoryId>
                                    <file>${EJB_LOCATION}</file>
                                    <url>http://nexus.example.com:8081/repository/maven-releases</url>
                                    <groupId>${project.parent.groupId}</groupId>
                                    <artifactId>${project.parent.artifactId}-EJB</artifactId>
                                    <version>${project.parent.version}</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <packagingExcludes>WEB-INF/classes/rebel.xml</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <overwrite>true</overwrite>
                            <outputDirectory>${basedir}/target/classes</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/test/resources</directory>
                                    <includes>
                                        <include>log4j2.xml</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>ant-build</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <property name="server.dir" value="${SERVER_DIR}" />
                                <property name="createEjbStubsScriptFile" value="${CREATE_EJB_STUBS_SCRIPT_FILE}" />
                                <property name="appClassesDir" value="${APP_CLASSES_DIR}" />
                                <property name="author" value="${project.organization.name}" />
                                <property name="maven.root" value="${project.parent.artifactId}" />
                                <property name="maven.war.artifactId" value="${project.artifactId}" />
                                <property name="maven.war.version" value="${project.parent.version}" />
                                <ant antfile="${basedir}/src/test/resources/ant/build.xml">
                                    <target name="run" />
                                </ant>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <executable>${IBM_JDK_1_8}/bin/javac</executable>
                    <compilerVersion>1.6</compilerVersion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>install</phase>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                   <!-- some config -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

ear 模块 pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example</groupId>
        <artifactId>Test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>Test-EAR</artifactId>
    <packaging>ear</packaging>

    <dependencies>
        <!-- WAR -->
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>Test-WAR</artifactId>
            <version>${project.parent.version}</version>
            <type>war</type>
        </dependency>
        <!-- some other dependencies -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <modules>
                        <!-- some jar modules -->
                        <webModule>
                            <groupId>com.example</groupId>
                            <artifactId>Test-WAR</artifactId>
                            <contextRoot>/Test</contextRoot>
                        </webModule>
                    </modules>
                    <version>6</version>
                    <finalName>${project.parent.artifactId}-${project.parent.version}</finalName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <executions>
                    <execution>
                        <id>deploy-ear</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <repositoryId>nexus-snapshots</repositoryId>
                            <file>target/${project.parent.artifactId}-${project.parent.version}.ear</file>
                            <url>http://nexus.example.com:8081/repository/maven-snapshots</url>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>ear</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我有两个配置文件 - dev(默认情况下处于活动状态)和 release(由发布插件激活)。首先,我在发布版本时遇到了 ant run(文件路径)的一些问题,所以我使用了两个定义了一些属性的配置文件,它们在 ant run 中使用。 Ant 脚本现在已正确执行,但我还有另一个问题:插件尝试两次上传某些发布文件导致错误:

执行 mvn release:prepare "-Darguments=-Dmaven.test.skip=true": log

执行 mvn release:perform "-Darguments=-Dmaven.test.skip=true": log

您可以看到表单日志,Test-WAR-0.0.1-sources.jar 正在上传两次。这是为什么?如何编辑我的配置以仅上传一次?

【问题讨论】:

  • 这些deploy:deploy-file 要求什么?您是否尝试使用deploy-file 部署构建结果?为什么跳过了正常的部署步骤?
  • @JFMeier deploy:deploy-file部署ant run生成的jar文件。跳过了正常部署,因为我只需要部署 ant run 生成的这两个 jar 文件,而不是整个 war 模块。这甚至可能吗?我不知道为什么在“deploy-ejb-client”执行时会发生战争部署,你能解释一下吗?
  • 这导致了 Ant 和 Maven 之间的奇怪混合,并可能导致各种问题。通常,您通过 Maven 为每个模块创建一个工件,然后在部署阶段自动部署该工件。
  • 清理 pom 很可能会解决问题,即开始删除每个 maven-deploy-plugin 和 maven-antrun-plugin。如果不成功,请分析该问题。

标签: maven pom.xml maven-release-plugin


【解决方案1】:

很可能你遇到了和我几年前一样的错误:

Maven deploy-file goal: Why does the first execution interfere with the second one?

尝试将 Maven 部署插件更新到版本 3.0.0-M1

【讨论】:

  • 有效!我从来没有想过。非常感谢!
猜你喜欢
  • 2013-03-11
  • 2011-10-07
  • 2013-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多