Why maven executable does not start?

I am creating a simple project, just to run the 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 get an error message:

 [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 is VALUE? I thought this was the name of the executable ...

When I use -Dexec.executable = VALUE, for example -Dexec.executable=calc , it works. Another problem is in the plugin docs:

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

But when I start with -Dexec.executable = calc-maven, wait until I close the calculator! Where is a separate process?

+4
source share
2 answers

Because you place a <configuration> inside a specific <execution> phase bound, this configuration parameter only applies to this particular binding. With the general mvn exec:exec it is not tied to any phase and therefore will only use the general configuration section for the plugin. So 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 fine if you invoke a life cycle that includes the generate-sources phase (e.g. mvn test , mvn install , mvn package ) and is actually more suitable there, as it allows other life cycle connections to the same plugin without interference.

+5
source

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

From the documentation :

Starting with Maven 2.2.0, each mojo, called directly from the command line, will have a default-cli execution identifier assigned to it, which allows you to configure this execution from the POM to use this default execution identifier.

In order for your error to be applied when running mvn exec:exec , you need to change the execution identifier 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 assembly with mvn exec:exec , you can instead move the <configuration> outside the <execution> block.

+8
source

Source: https://habr.com/ru/post/1385489/


All Articles