java maven exec-maven-plugin not executing on mvn clean install

exec-maven-plugin, java, jenkins, maven

Solution

With your plugin defined under the `<pluginManagement>`, you are actually telling maven which version of the plugin you will use throughout your project when you will invoke the plugin. I would normally expect the `<pluginManagement>` tag to be present in the parent pom.

To invoke the plugin - simply put the `<plugins/>` element. It may or may not be inherited from a

Hence to use the plugin, you just need to invoke the plugin by putting

<plugins>
        <plugin>            
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>build-test-environment</id>
                    <phase>generate-test-resources</phase>          
                    <goals>
                        <goal>java</goal>           
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>main.java._tools.BuildTestEnvironment</mainClass>
            </configuration>
        </plugin>
    ...AnyOtherPlugin
    <plugins>

without any `<pluginManagement>` tag

Problem

Follow-up to a previous question: Maven run class before test phase: exec-maven-plugin exec:java not executing class. I am running jUnit4 tests, built with maven, on a jenkins box. I need to run a specific main-method java program before before the test phase of my build. The intent is to restore a test database before the tests run. If I run the exact phase this exec is assigned to, my class executes as expected; but when I run the whole build, my class does not execute: Specifically, it runs with: `mvn -X exec:java generate-test-resources` But does not run with: `mvn -X -e install` -- or -- `mvn -X -e clean install` pom.xml: My pom.xml file includes: ``` <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>build-test-environment</id> <phase>generate-test-resources</phase> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>main.java._tools.BuildTestEnvironment</mainClass> </configuration> </plugin> </plugins> </pluginManagement> ``` Lifecycle default: I have not futzed with maven's lifecycle. The log reports it as: ``` [DEBUG] Lifecycle default -> [ validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy ] ```

Original source

Related problems