为什么maven可执行文件不运行?

use*_*818 6 executable maven

我创建了简单的项目,只用于启动计算器:

<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>
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时:

mvn exec:exec
Run Code Online (Sandbox Code Playgroud)

我收到错误:

[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'
Run Code Online (Sandbox Code Playgroud)

但是我有 :

<configuration>
    <executable>calc</executable>
</configuration>
Run Code Online (Sandbox Code Playgroud)

VALUE必须是什么?我以为它是可执行文件的名称......

当我使用-Dexec.executable = VALUE时-Dexec.executable=calc- 它的工作原理.另一个问题 - 在关于插件的文档中:

exec:exec execute programs and Java programs in a separate process. 
Run Code Online (Sandbox Code Playgroud)

但当我运行-Dexec.executable = calc - maven等我关闭计算器时!哪里有独立的流程?

Mar*_*tin 10

配置是正确的,但Maven不使用它 - 因此令人困惑的错误消息:)

文档:

从Maven 2.2.0开始,直接从命令行调用的每个mojo将分配一个default-cli的执行ID ,这将允许使用此默认执行Id从POM配置该执行.

为了在运行时应用您的confugration mvn exec:exec,您需要将执行ID更改为default-cli:

...
<executions>
    <execution><!-- Run our version calculation script -->
        <id>default-cli</id>
        ...
Run Code Online (Sandbox Code Playgroud)

如果您希望能够运行插件作为构建的一部分,并mvn exec:exec,你可以改为移动<configuration><execution>块.


Don*_*ows 9

因为您将<configuration>内部<execution>绑定到绑定到某个阶段的特定内容,所以该配置设置仅在执行该特定绑定执行时适用.通用mvn exec:exec,它不受任何阶段的约束,因此只使用插件的通用配置部分.因此,这应该工作:

    <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>
Run Code Online (Sandbox Code Playgroud)

但是,如果你调用一个生命周期,其中包括你写的版本应该只是正常工作generate-sources阶段(例如mvn test,mvn install,mvn package)实际上是在更适合在那里,因为它允许在同一插件的其他生命周期绑定无干扰.