具有多个子模块的父项目中的Maven货物:tomcat端口号正在使用中

时间:2015-11-23 11:14:54

标签: maven tomcat maven-failsafe-plugin maven-cargo integration-testing

我使用maven cargo plugin和maven failsafe插件来运行我的集成测试。 我有一个父项目和两个子模块项目:

IT-parent
     --> IT-submodule1
     --> IT-submodule2

我的问题是Maven Cargo在父项目上启动了tomcat,然后子模块启动和停止tomcat。

父pom.xml

<build>
  <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.8.1</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                      <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>   
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.15</version>
                <configuration>
                    <container>
                        <containerId>tomcat7x</containerId>
                        <type>installed</type>
                        <home>${CATALINA_HOME}</home>
                    </container>
                    <configuration>
                        <type>existing</type>
                        <home>${CATALINA_HOME}</home>
                        <properties>
                                  <cargo.servlet.port>7080</cargo.servlet.port>
                                  <cargo.tomcat.ajp.port>7009</cargo.tomcat.ajp.port>
                                  <cargo.jvmargs>-Xms128m -Xmx512m -XX:MaxPermSize=256m</cargo.jvmargs>
                    </configuration>
                      <deployables>
                        ...
                      </deployables>
            </configuration>
            <executions>
                <!-- start server before integration tests -->
                <execution>
                    <id>start-container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deployer-deploy</goal>
                        <goal>start</goal>
                    </goals>
                </execution>

                <!-- stop server after integration tests -->
                <execution>
                    <id>stop-container</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>deployer-undeploy</goal>
                        <goal>stop</goal>
                    </goals>
                </execution>
        </executions>
      </plugin>
  </plugins>

子模块pom.xml没有<build>部分。

有没有办法在父项目中使用maven货物启动tomcat,子模块只在该容器中运行集成测试。所以我不会有一系列启动/停止tomcat等于子模块的数量。

1 个答案:

答案 0 :(得分:0)

1.Parent pom.xml
Move maven-failsafe-plugin to plugin management:

    <pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.8.1</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                      <goal>integration-test</goal>
                    </goals>
                    ..
                    ..
2.Parent pom.xml
    + IT-submodule1
    + IT-submodule2

Activate maven-failsafe-plugin in IT-submodule1 =>
Add declaration 

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
        <plugin>
    </plugins>