4
    <profile>
        <id>integration-tests</id>
        <activation>
            <property>
                <name>integrations</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.4.0</version>
                    <executions>
                        <execution>
                            <id>script-chmod</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>chmod</executable>
                                <arguments>
                                    <argument>+x</argument>
                                    <argument>integration-test-docker/integrations.sh</argument>
                                </arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>script-exec</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>integration-test-docker/integrations.sh</executable>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

This profile has more things in it, but I included only what I want to run. How can I execute this particular goal, of this particular plugin?

I tried mvn exec:exec but I get this

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (default-cli) on project ando: The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec are missing or invalid -> [Help 1]

Moreover, the error output indicates the version 1.3.2, but I'm using 1.4.0.

4

1 回答 1

9

您在调用 the 的exec目标时会出错,exec-maven-plugin因为它的配置(您的意思)是配置文件的一部分,默认情况下它是不活动的,并且它没有被您的执行激活mvn exec:exec

如果您尝试通过其属性激活(根据配置)或显式(通过-P选项)激活配置文件,那么 Maven 将知道您提到的 Exec Maven 插件:

mvn exec:exec -Pintegration-tests

或者

mvn exec:exec -Dintegrations=true

因此,配置文件将处于活动状态,并且您的 Exec Maven 插件配置将成为构建的一部分。

但是,您正在配置插件的两次执行,并且没有全局配置,因此它也会再次失败。

一个section in 或out of sub-section的元素是有区别的:out,它将默认应用于所有执行和命令行执行;在,它将应用于应用的特定执行(覆盖或与任何默认执行合并,如果提供)。configurationpluginexecution

如果您想同时运行这两个执行,您可以只激活配置文件:

mvn clean verify -Pintegration-tests

或者

mvn clean verify -Dintegrations=true

但是,它将执行配置文件的全部内容以及整个构建,直到指定的phase.

如果您只想exec从命令行执行插件目标 ( ),那么您需要指定一个默认配置(但只有一个),如下所示:

<profile>
    <id>integration-tests</id>
    <activation>
        <property>
            <name>integrations</name>
            <value>true</value>
        </property>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <configuration>
                    <!-- here your default configuration -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

默认配置将应用于命令行执行。

或者,您也可以覆盖默认执行 id ( default-cli),该默认执行 id ( ) 由命令行中的每个插件执行使用,您可以将其视为问题中提到的错误的一部分。因此,您可以仅为该执行提供特定配置,而不是为所有其他(如果有)执行提供特定配置(假设它们不会提供自己的配置)。这是一个例子:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.4.0</version>
    <executions>
        <execution>
            <id>default-cli</id>
            <configuration>
                <!-- here your specific command line execution -->
            </configuration>
        </execution>
    </executions>
</plugin>

如果您想从命令行执行这两个执行并且仅执行这些执行(因此,不作为 Maven 阶段的一部分),您可以检查有关该主题的答案(简而言之:自 Maven 3.3.1以来可能,否则建议为早期版本提供)。

因此,执行将如下所示:

mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:exec@script-chmod -Dintegrations=true

笔记:

  • 我再次激活配置文件以将执行作为构建的一部分
  • 这次我没有传递插件别名,exec和期望的目标 ,exec而是它的完整 Maven GAV (groupId, artifactId, version) 在通用 Maven 模式中用于依赖项(:分隔),所以我们得到org.codehaus.mojo:exec-maven-plugin:1.4.0,然后传递目标,所以我们得到了额外的:exec,然后使用上面提到的新特性和新的@操作符,我传递了所需的执行 ID(在 POM 中定义)。
于 2016-01-24T20:15:10.687 回答