2016-01-24 21 views
3
<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> 

此配置文件中有更多的东西,但我只包括我想运行的东西。我怎样才能执行这个特定的目标,这个特定的插件?运行一个配置文件中的插件的目标

我试图mvn exec:exec,但我得到这个

[错误]未能执行目标 org.codehaus.mojo:上 项目EXEC(默认CLI):EXEC-Maven的插件:1.3.2安藤:参数 '可执行' 为目标 org.codehaus.mojo:EXEC-行家-插件:1.3.2:EXEC缺失或无效 - > [帮助1]

此外,错误输出指示版本1.3.2,但我正在使用1.4.0

回答

7

你调用的exec-maven-pluginexec目标,因为它的配置(你的意思是一个)是profile默认情况下是不活跃的一部分,它不是由您的执行mvn exec:exec激活得到一个错误。

如果您尝试激活通过其属性激活配置文件(根据配置)或明确(通过-P选项),然后Maven会知道你提到的这Exec的Maven插件:

mvn exec:exec -Pintegration-tests 

mvn exec:exec -Dintegrations=true 

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

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

没有为或缩小execution子部分的plugin部分configuration元件之间的difference:出来,它会被默认应用到所有执行和命令线处决;它将应用于应用的特定执行(覆盖或与任何缺省合并,如果提供)。

如果你想同时运行处决,你就可以只启动的情景:

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> 

缺省设置将被应用到命令行执行。

或者,也可以覆盖default execution iddefault-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> 

如果要执行的命令行两次执行,只有这些执行(因此,不能作为一个Maven阶段的一部分),您可以检查该主题this answer(简称:它是可能的,因为Maven 3.3.1,否则对早期版本提供建议)。

因此,执行将是如下:

mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:[email protected] -Dintegrations=true 

注:

  • 我再次激活轮廓具有执行作为构建
  • 这一次的一部分我没有通过插件aliasexec和期望的目标exec,但它的完整Maven GAV(groupId,artifactId,版本)在通用Maven模式中依赖关系(:),所以我们得到org.codehaus.mojo:exec-maven-plugin:1.4.0,然后通过目标,所以我们得到额外的:exec,然后使用上面提到的新功能和新的@运算符我传递所需的执行ID(在POM中定义)。
相关问题