2016-03-25 55 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

相關問題