maven - 使用 Maven Exec 插件执行多个命令

标签 maven build-management maven-exec-plugin

我在使用 Maven Exec 插件时遇到了一些困难。我想使用该插件执行两个单独的 mvn 命令,因此我只需要执行 mvn exec:exec 即可执行所有命令。

以下两个命令单独运行效果良好:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <configuration>
        <executable>mvn</executable>
        <arguments>
            <argument>clean</argument>
        </arguments>
    </configuration>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <configuration>
        <executable>mvn</executable>
        <arguments>
            <argument>package</argument>
        </arguments>
    </configuration>
</plugin>

这是我尝试将两者结合起来以便用一个命令执行它们:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>

    <executions>
        <execution>
            <id>id1</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>clean</argument>
                </arguments>
            </configuration>
        </execution>

        <execution>
            <id>id2</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>package</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>

</plugin>

不幸的是,当我现在执行 mvn exec:exec 时,我收到以下错误消息:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProjet 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:exec (default-cli) @ MyProject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.787 s
[INFO] Finished at: 2017-09-26T09:56:57+01:00
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (default-cli) on project MyProject: The parameter 'executable' is missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

最佳答案

当您运行mvn exec:exec时在命令行上,它运行 <execution><id>default-cli 。这解释了错误消息,因为没有执行 <id>default-cli</id>有一个 <executable>在 POM 中配置。

要解决您的问题,请查看 Guide to Configuring Plug-ins 。它解释了如何使用<id>从命令行执行目标。除了 default-cli :

mvn exec:exec@id1 exec:exec@id2

关于maven - 使用 Maven Exec 插件执行多个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46420887/

相关文章:

maven - 无法在启用 LDAP 的情况下使用加密密码部署 Artifact

java - Ant 和 Maven 之间的差异

eclipse - 如何在 eclipse ant 编辑器中启用撤消?

java - mvn 执行 :java to run a java file in an external JAR file

jsp - 在 CQ5.6.1 项目中使用 Sling Taglib 1.3 版

java - 服务中的空 Autowiring Spring Bean(Cassandra 存储库)

maven - 如何使用主 pom 文件检查 Web 应用程序的所有模块并构建所有模块

java - maven:执行而不实际构建任何东西

java - 无法执行目标org.springframework.boot :spring-boot-maven-plugin:2. 1.0.RELEASE