rwfbc
rwfbc

Reputation: 998

Run exec-maven-plugin on demand only

Is there a way to configure maven (in general) or the exec-maven-plugin so that it is executed on demand only, but linked up to (and including) test?

I have a test main (java) that I use for ad-hoc testing. I can run it fine from within Eclipse. But I also want to run it from the command line.

However, I do not want it to run with the unit tests (test phase).

But it has to be staged after the test phase, because it uses code from the test subtree and it uses the test classpath.

Here is what I have. It works fine, except that it runs as part of the test phase.

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
            <execution>
                <id>adhoc-domain-test</id>
                <phase>test</phase>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.abc.test.AdHocTest</mainClass>
            <classpathScope>test</classpathScope>
        </configuration>
    </plugin>

If I change the phase to (eg) verify, it still gets executed on mvn install.

Upvotes: 3

Views: 1935

Answers (1)

gjoranv
gjoranv

Reputation: 4721

To run a plugin on demand only, you can wrap the plugin inside a profile that is not active by default, like this:

<profiles>
    <profile>
        <id>my-profile</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                ...
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

The profiles element goes directly under the project element. You can now run the plugin like this:

mvn -P my-profile ...

Upvotes: 2

Related Questions