Why maven executable doesn't run?

10,627

Solution 1

Because you put the <configuration> inside a particular <execution> that is bound to a phase, that configuration setting only applies when executing that particular bound execution. With the general mvn exec:exec, it's not bound to any phase and so would only use the common configuration section for the plugin. Thus, this should work:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
            <execution><!-- Run our version calculation script -->
                <id>Version Calculation</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>calc</executable>
        </configuration>
    </plugin>

However, the version you wrote should work just fine if you invoke a lifecycle that includes the generate-sources phase (e.g., mvn test, mvn install, mvn package) and is in fact more suitable there, as it allows for other lifecycle bindings of the same plugin without interference.

Solution 2

The configuration is correct, but Maven doesn't use it - hence the confusing error message :)

From the documentation:

Starting in Maven 2.2.0, each mojo invoked directly from the command line will have an execution Id of default-cli assigned to it, which will allow the configuration of that execution from the POM by using this default execution Id.

For your confugration to apply when you run mvn exec:exec, you need to change the execution id to default-cli:

...
<executions>
    <execution><!-- Run our version calculation script -->
        <id>default-cli</id>
        ...

If you want to be able to run the plugin as part of the build and with mvn exec:exec, you could instead move the <configuration> outside the <execution> block.

Share:
10,627
user710818
Author by

user710818

Updated on June 27, 2022

Comments

  • user710818
    user710818 over 1 year

    I have create simple project, only to launch calculator:

    <project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test.maven.executable</groupId>
    <artifactId>exe1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>TestExe</name>
    <description>test execute with maven different excutables</description>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution><!-- Run our version calculation script -->
                        <id>Version Calculation</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>calc</executable>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    </project>
    

    But when I run:

    mvn exec:exec
    

    I receive error:

    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] One or more required plugin parameters are invalid/missing for 'exec:exec'
    
    [0] Inside the definition for plugin 'exec-maven-plugin' specify the following:
    
    <configuration>
      ...
      <executable>VALUE</executable>
    </configuration>
    
    -OR-
    
    on the command line, specify: '-Dexec.executable=VALUE'
    

    But I have :

    <configuration>
        <executable>calc</executable>
    </configuration>
    

    What the VALUE must be? I thought that it is the name of executable...

    When I use -Dexec.executable=VALUE like -Dexec.executable=calc - it works. Also another problem - in docs about plugin:

    exec:exec execute programs and Java programs in a separate process. 
    

    But when I run with -Dexec.executable=calc - maven wait when I close calculator! Where there separate process?

  • Donal Fellows
    Donal Fellows almost 12 years
    For the subsidiary question, that's how the exec plugin works. You probably don't want to run calc normally, but it's fine for testing out how to use these things. (It's definitely a separate process. Different binary, different process id, OS tools will see it separately. It's just that the exec plugin waits for the subprocess it creates to finish, i.e. for you to quit it.)