Fabio Formosa
Fabio Formosa

Reputation: 1084

Maven cargo in parent project with multiple submodules: tomcat port number is in use

I use maven cargo plugin and maven failsafe plugin to run my integration tests. I have a parent project and two submodule projects:

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

My problem is Maven Cargo on parent project starts the tomcat, then also the submodules start and stop tomcat.

Parent 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>

Submodule pom.xml has no <build> section.

Is there a way to start tomcat with maven cargo once at parent project and submodules run only integration tests in that container. So I wouldn't have a series of start/stop tomcat equals to the number of submodules.

Upvotes: 1

Views: 568

Answers (1)

question_maven_com
question_maven_com

Reputation: 2475

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>

Upvotes: 0

Related Questions