Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - determine order of different plugin goals in the same phase

The following snippet is an excerpt of the configuration of the maven-cargo plugin, but the question is independent from that specific plugin.

            <executions>
                <execution>
                    <id>start</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy</goal>
                        <goal>start</goal>
                    </goals>
                </execution>
            </executions>

This configuration (lets simply call it plugin A) will wait till pre-integration-test phase, then fire its goals deploy and start (in that order).

Say I have another plugin B which is relevant in the same phase. What are my options to

  1. execute plugin B's goals before (after) A? (someStuff - > deploy -> start)
  2. execute plugin B's goals in-between plugin A's goals (deploy -> someStuff -> start)

I figure that the answer to (1) is here, linking the order of the goals to the order of the plugin definition in the POM. But I have no idea about (2).

like image 363
Jan Groth Avatar asked Feb 22 '12 09:02

Jan Groth


People also ask

Does the order of plugins matter Maven?

Sequence ultimately does matter because each plugin will affect how the next one down the line behaves. Place a distortion before a chorus and you're going to get a lush distortion.

How do I run a specific goal in Maven?

Run a Maven goal from the context menu In the Maven tool window, click Lifecycle to open a list of Maven goals. Right-click the desired goal and from the context menu select Run 'name of the goal'. IntelliJ IDEA runs the specified goal and adds it to the Run Configurations node.

Does Maven allow third party plugins?

However, as previously mentioned, the user may have a need for third-party plugins. Since the Maven project is assumed to have control over the default plugin groupId, this means configuring Maven to search other groupId locations for plugin-prefix mappings. As it turns out, this is simple.


1 Answers

You are right about (1). If two plugins are to be executed on the same phase, then they will be executed in the order they are declared in pom.xml.

I'm not 100% sure about the (2), but I think it's impossible without some hacks, like using exec-maven-plugin, for example:

<!-- deploy -->
<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <executions>
    <execution>
      <id>deploy</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>deploy</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- do something -->
<plugin>
  <groupId>some_other_plugin</groupId>
  <artifactId>some_other_plugin</artifactId>
  <executions>
    <execution>
      <id>someStuff</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>some_goal</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- start -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>mvn</executable>
        <commandlineArgs>org.codehaus.cargo:cargo-maven2-plugin:start -Dparam=value</commandlineArgs>
      </configuration>
    </execution>
  </executions>
</plugin>
like image 141
Andrew Logvinov Avatar answered Nov 10 '22 16:11

Andrew Logvinov