Graham
Graham

Reputation: 4295

Make maven run one task before another when running a single plugin

I've got a project set up using the Maven Cargo plugin to launch Tomcat with my webapp deployed in it, along with some other webapps that are needed for support. This works great. Unfortunately, when I run "mvn cargo:run" it doesn't do a build first, but instead just actually starts Tomcat running the code the last time I did do a build.

Previously I used the tomcat7 plugin instead, and that did do a build first and always ran the current version of the source code. As such, I could change my code and run "mvn tomcat7:run" and know that the code changes had been built and were running.

I can't find any way with the Cargo plugin to make it do this, but is there some way with Maven to make it at least run the Package phase when I run a specific plugin so that it will build the WAR file correctly first?

Upvotes: 0

Views: 1342

Answers (3)

hzpz
hzpz

Reputation: 7966

A completely different approach would be to use the exec-maven-plugin to execute multiple goals with one command:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>clean</argument>
                    <argument>compile</argument>
                    <argument>cargo:run</argument>
                </arguments>
            </configuration>
        </plugin>
        <!-- more plugins... -->
    </plugins>
</build>

This way, you would only have to call

mvn exec:exec

to clean, compile and run your application.

Upvotes: 0

hzpz
hzpz

Reputation: 7966

The Tomcat plugin automatically invokes the compile phase prior to executing itself. The Cargo plugin won't do that. In order to compile your code before executing the plugin, you need to run

mvn clean compile cargo:run

If you want to start and stop the container automatically before and after your integration tests, you can also bind cargo:start and cargo:stop to Maven's lifecycle phases. See Automatically executing and stopping the container when running mvn install for details.

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97517

Here is a full example how to integrate the start via Cargo in the usual build. https://github.com/khmarbaise/maui/tree/master/src/main/resources/it-example-container. You can start the integration tests via mvn -Prun-its clean verify which might be better

Upvotes: 0

Related Questions