34

Is it possible to invoke a maven-exec-plugin (or any other plugin's) execution by its id from the command line?

Let's say my pom.xml file looks like this:

<project>
[...]
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>foo</id>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase></phase>
            <configuration>
                <executable>echo</executable>
                <arguments>
                    <argument>foo</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>bar</id>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase></phase>
            <configuration>
                <executable>echo</executable>
                <arguments>
                    <argument>bar</argument>
                </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
[...]
</project>

Now is it possible to call

mvn exec:exec

with some added magic to run execution "foo"?

For the curious there is an alternative solution using profiles available here: http://www.mail-archive.com/user@mojo.codehaus.org/msg00151.html

Maciej Biłas
  • 1,966
  • 2
  • 18
  • 20
  • 3
    I cannot get the plugin to work with the in the tag. It does however work putting it just outside the tag. The error is "The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec are missing or invalid" – avanderw Sep 21 '12 at 08:47
  • Note that in the above "alternative solution using profiles", the `` tags are missing. – zb226 Jan 23 '15 at 07:09

4 Answers4

29

It is now possible, starting from Maven 3.3.1: see improvement MNG-5768 and Maven 3.3.1 release notes

You can call a specific execution configuration with this syntax:

mvn exec:exec@foo
slanglois
  • 404
  • 5
  • 9
16

No, it's not possible. Executions are for binding to the lifecycle (i.e. they are not designed to be invoked on the command line). So you'll have to use the profile trick described in the link that you provided.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
11

Not mentioned here is that, as of Maven 2.2.0, if you give an execution of any plugin the id "default-cli", then when you run that plugin from the command line, that configuration is used. You're limited to only one default execution of each plugin, but it's a start.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
0

I think if you write execute the goal:

org.codehaus.mojo:exec-maven-plugin:¿Version?:exec

it worked for me in eclipse maven plugin.

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
migueloop
  • 525
  • 9
  • 21