2016-02-23 64 views
0

我正在将插件集成到多模块项目中。仅通过激活在父POM中运行Maven目标

我使用的第三方插件基本上只需要通过从父项目运行(基于我的理解和使用它)。我试图通过使用profile做到这一点,就像这样:

<profiles> 
    <profile> 
     <id>run-my-guy</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.myproject</groupId> 
        <artifactId>myproject-maven-plugin</artifactId> 
        <executions> 
         <execution> 
          <phase>package</phase> 
          <goals> 
           <goal>runThing</goal> 
          </goals> 
          <inherited>false</inherited> 
         </execution> 
        </executions> 
        <inherited>false</inherited> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

我有几个<inherited>false</inherited>,但如果我跑mvn help:all-profiles我仍然可以看到每一个模块在此配置文件。如果我运行我的mvn package -P run-my-guy,我看到这会在每个子项目中执行。我希望能够激活此功能,并且我不希望它在默认情况下处于启用状态。

如果我试图将其添加到<build>部分,像这样:

<build> 
    <plugins> 
    <plugin> 
     <groupId>com.myproject</groupId> 
     <artifactId>myproject-maven-plugin</artifactId> 
     <inherited>false</inherited> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
      <goal>runThing</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

在这里,我也有一些<inherited>false</inherited>,只是为了尝试和执行的插件和执行不继承。但是,如果我运行package阶段或包含该阶段的任何项目,则会包含runThing目标。

如何仅通过激活(如配置文件或某些其他功能,或者仅通过明确运行目标)来运行目标,并且仅在父级中运行?

回答

0

"Run a single Maven plugin execution?"的答案所示,现在可以(因为Maven 3.3.1)为直接目标调用指定执行标识。

的pom.xml

<build> 
    <plugins> 
    <plugin> 
     <groupId>com.myproject</groupId> 
     <artifactId>myproject-maven-plugin</artifactId> 
     <inherited>false</inherited> 
     <executions> 
     <id>myproject-exec-id</id> <!-- note the execution Id --> 
     <execution> 
      <phase>none</phase> 
      <goals> 
      <goal>runThing</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

然后从命令行调用目标使用可选@executionId参数:

mvn myproject:[email protected]