Search code examples
mavenmaven-pluginmaven-profilesmaven-lifecycle

does maven profile configured for integration phase execute during build life cycle?


Here is the condensed snippet of pom.xml from my project

   <profiles>

            <profile>
                <id>run-tests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.google.code.maven-replacer-plugin</groupId>
                            <artifactId>replacer</artifactId>
                            <version>1.5.2</version>
                            <executions>
                                <execution>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>replace</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <includes>
                                   ......
                                </includes>

                                <replacements>
                                    <replacement>
                                       .......
                                    </replacement>
                                </replacements>
                            </configuration>
                        </plugin>

                   <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>2.18.1</version>
                            <configuration>
                                ......
                            </configuration>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>integration-test</goal>
                                        <goal>verify</goal>
                                    </goals>
                                    <phase>integration-test</phase>
                                </execution>
                            </executions>
                        </plugin>
                     </plugins>
    </build>
</profile>
</profiles>

I have two questions:

1) when I execute mvn clean package -Prun-tests, what happens? I expected none of these plugin goals to execute here because they are bound to integration-test phase. But I see these goals executed why?

2) what does having two goals in execution block mean? please see above in failsafe-plugin

Thanks


Solution

  • A partial answer:

    1) No Way. Unless you also have these plugins configured in the main build section to be run in phases up to package.

    How did you determine that the plugins had run? Do you have something such as the following in the maven output?

    [INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default)

    [INFO] --- maven-failsafe-plugin:2.18.1:verify (default)

    2) That means that the two goals (mojos) will be executed in the integration-test phase. First the integration-test goal, immediately followed by the verify goal.

    Comment: integration-test goal is by default bound to the integration-test phase, whereas the verify goal is bound to the verify phase. So you could have configured the failsafe plugin this way:

        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
    

    Note that the phase is ommited