Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why maven executable doesn't run?

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?

like image 518
user710818 Avatar asked Dec 09 '11 07:12

user710818


2 Answers

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.

like image 82
Martin Avatar answered Sep 30 '22 16:09

Martin


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.

like image 44
Donal Fellows Avatar answered Sep 30 '22 17:09

Donal Fellows