2016-03-25 54 views
0

我对詹金斯输出有点困惑。对詹金斯Maven配置文件 - 如何为父级运行插件一次以及为模块运行更多插件?

工作:(底部缩短的pom.xml)

mvn deploy -Pprofile1 

我所有的插件将运行4次:

  • 父/ pom.xml的
  • 父/模块1/pom.xml
  • parent/module2/pom.xml
  • parent/module3/pom.xml

我需要:

  • 第一Maven的插件:只有在父pom.xml中运行一次
  • 第二Maven的插件:运行 POM .xml

Why:

  • first-maven-plugin:将运行在阶段:初始化 - >相当长的清理操作。不要这4次
  • second-maven-plugin:将运行在阶段:包 - >所有pom的necesaary。

父pom.xml的

<project ...> 

    <groupId>com.test.parent</groupId> 
    <modelVersion>4.0.0</modelVersion> 
    <artifactId>parent</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>parent</name> 

    <modules> 
     <module>module1</module> 
     <module>module2</module> 
     <module>module3</module> 
    </modules> 

    <profiles> 
     <profile> 
      <id>profile1</id> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>com.test.plugin</groupId> 
         <artifactId>first-maven-plugin</artifactId> 
         <version>1.0.0-SNAPSHOT</version> 
         <execution> 
          <id>execution1</id> 
          <phase>initialize</phase> 
          <goals> 
           <goal>doit</goal> 
          </goals> 
         </execution> 
        </plugin> 
        <plugin> 
         <groupId>com.test.plugin2</groupId> 
         <artifactId>second-maven-plugin</artifactId> 
         <version>1.0.0-SNAPSHOT</version> 
         <execution> 
          <id>another</id> 
          <phase>package</phase> 
          <goals> 
           <goal>goforit</goal> 
          </goals> 
         </execution> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 

</project> 
+1

做这两个插件有任何'skip'选项? –

+0

插件没有跳过选项。它们是通用的,因为它们可以在多个项目上运行。 –

回答

1

首先,如果你定义它继承到所有的孩子比它正好表现你希望这意味着它是每个POM执行父插件(或换句话说,每个模块都不重要,如果它是一个孩子或不)。

你的插件的问题是他们处理的用例不是很好。因为你说的第一个first-maven-plugin只应在根级别运行(你所说的清理操作意味着除此之外,我不明白...删除目标文件夹?)

而第二个插件second-maven-plugin应该为所有运行POM的?这不是很准确,因为你的意思是说,所有的子模块都使用pom包装pom?但我认为你的意思是所有的孩子都有包装jar

除了上述我不确定您的配置文件的使用是否仅基于缺乏处理正确的用例。

上述结果我会得出结论,你需要改变你的插件的实现。

如果你喜欢有只能在这样的多模块结构,这可以在一个非常简单的方式处理您的插件这样的根级插件运行:

public void execute() 
    throws MojoExecutionException, MojoFailureException 
{ 

    if (mavenProject.isExecutionRoot()) { 

    } else { 

    } 

.. 

通过使用插件上面可以决定它是否在根级别上运行。

所以你first-maven-plugin可以使用以下命令:

public void execute() 
    throws MojoExecutionException, MojoFailureException 
{ 

    if (!mavenProject.isExecutionRoot()) { 
     getLog().info("Not running at root level"); 
     return; 
    } 
    // here the time consuming operations   
.. 

和你second-maven-plugin做oposite:

public void execute() 
    throws MojoExecutionException, MojoFailureException 
{ 

    if (mavenProject.isExecutionRoot()) { 
     getLog().info("Not running at root level"); 
     return; 
    } 
    // here the operation on the childs. 
.. 

行为可以通过以下进行改进:

public void execute() 
    throws MojoExecutionException, MojoFailureException 
{ 

    if (!mavenProject.isExecutionRoot()) { 
     getLog().debug("Not running at root level"); 
     return; 
    } 

    if ("pom".equals(project.getPackaging())) { 
     getLog().debug("Ignoring pom packaging."); 
     return; 
    } 
    // ..now the operations you would like to do... 

所以如果你有几个级别的模块层次结构,你可以忽略它e pom包装零件或其他零件等

最后但并非最不重要。你的插件归档了什么?

0

您可以在第一插件配置使用<inherited>false<inherited>,为我工作:

  <build> 
      <plugins> 
       <plugin> 
        <groupId>com.test.plugin</groupId> 
        <artifactId>first-maven-plugin</artifactId> 
        <version>1.0.0-SNAPSHOT</version> 
        <inherited>false<inherited> 
        <execution> 
         <id>execution1</id> 
         <phase>initialize</phase> 
         <goals> 
          <goal>doit</goal> 
         </goals> 
        </execution> 
       </plugin> 
       <plugin> 
        <groupId>com.test.plugin2</groupId> 
        <artifactId>second-maven-plugin</artifactId> 
        <version>1.0.0-SNAPSHOT</version> 
        <execution> 
         <id>another</id> 
         <phase>package</phase> 
         <goals> 
          <goal>goforit</goal> 
         </goals> 
        </execution> 
       </plugin> 
      </plugins> 
     </build> 

https://stackoverflow.com/a/1671175

相关问题