在多模块项目上使用Maven发布插件

问题描述 投票:1回答:1

我有一个包含两个模块的多模块项目: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>

war模块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(由release插件激活)。首先,发布版本时,我在使用蚂蚁运行时遇到了一些问题(文件路径),因此我使用了两个已定义了一些属性的配置文件,这些配置文件已在蚂蚁运行中使用。蚂蚁脚本现在可以正确执行,但是我还有另一个问题:插件尝试上载两次发行文件两次,这会导致错误:

执行mvn版本:准备“ -Darguments = -Dmaven.test.skip = true”:log

执行mvn版本:执行“ -Darguments = -Dmaven.test.skip = true”:log

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

maven pom.xml maven-release-plugin
1个回答
0
投票

[您很有可能遭受与几年前一样的错误:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.