在配置文件中运行插件的目标

Alk*_*ris 3 pom.xml maven-3 maven exec-maven-plugin maven-profiles

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

此配置文件中包含更多内容,但我只包含了我想要运行的内容.如何执行此特定插件的特定目标?

我试过mvn exec:exec但是我明白了

[错误]无法执行目标org.codehaus.mojo:exec-maven-plugin:1.3.2:exec(default-cli)on project ando:目标org.codehaus.mojo的参数'executable':exec-maven-插件:1.3.2:exec丢失或无效 - > [帮助1]

此外,错误输出表明版本1.3.2,但我正在使用1.4.0.

A_D*_*teo 7

您在调用the的exec目标时遇到错误,exec-maven-plugin因为它的配置(您所指的那个)是配置文件的一部分,默认情况下它不是活动的,并且它不会被您的执行激活mvn exec:exec.

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

mvn exec:exec -Pintegration-tests
Run Code Online (Sandbox Code Playgroud)

要么

mvn exec:exec -Dintegrations=true
Run Code Online (Sandbox Code Playgroud)

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

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

子部分内或外部的元素之间存在差异:out,默认情况下将应用于所有执行和命令行执行; 在,它将应用于应用的特定执行(覆盖或与任何默认的一起合并,如果提供).configurationpluginexecution

如果要运行两个执行,则可以只激活配置文件:

mvn clean verify -Pintegration-tests
Run Code Online (Sandbox Code Playgroud)

要么

mvn clean verify -Dintegrations=true
Run Code Online (Sandbox Code Playgroud)

但是,它将执行配置文件的整个内容以及整个构建直到指定的内容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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

如果你想从命令行执行两次执行而只执行这些执行(因此,不作为Maven阶段的一部分),你可以检查一下这个主题的答案(简而言之:从Maven 3.3.1开始就可以了,否则就是一个建议提供早期版本).

因此,执行如下:

mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:exec@script-chmod -Dintegrations=true
Run Code Online (Sandbox Code Playgroud)

注意:

  • 我再次激活配置文件以将执行作为构建的一部分
  • 这次我没有传递插件别名,exec和期望的目标,exec但它的完整Maven GAV(groupId,artifactId,版本)在依赖的公共Maven模式中(:分开),所以我们得到org.codehaus.mojo:exec-maven-plugin:1.4.0,然后传递目标,所以我们得到了额外的:exec,然后使用上面提到的新功能和新的@运算符我传递了所需的执行ID(在POM中定义).