2016-12-02 114 views
0

我有一個多模塊項目。在父POM(這不是聚合器POM)中,我使用的是maven-javadoc-plugin。它有兩個處決,分別在package階段,一個爲jar目標,另一個爲aggregate-jar目標。如何讓maven-javadoc-plugin生成多個jar文件?

這很好地生成了構建中所有(非測試)類的完整集合Javadoc jar。

我需要做的就是生成TWO Javadoc jars,就像它現在正在生成的一樣,但是另一個包含有限的一組模塊,並且可能排除特定的包或類。

我想也許這需要爲「聚合jar」任務添加兩個「執行」元素,但具有不同的配置值。這似乎沒有做任何事情。它只生成一個單獨的Javadoc樹,用於「所有」類。我如何完成這項工作?

這是我試圖做到這一點:

  <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <version>2.10.4</version> 
      <configuration> 
       <additionalparam>-Xdoclint:none</additionalparam> 
      </configuration> 
      <executions> 
       <execution> 
        <id>module-javadoc-jar</id> 
        <phase>package</phase> 
        <goals> 
         <goal>jar</goal> 
        </goals> 
        <configuration> 
         <show>protected</show> 
         <detectLinks>true</detectLinks> 
        </configuration> 
       </execution> 
       <execution> 
        <id>aggregated-documentation-all</id> 
        <phase>package</phase> 
        <inherited>false</inherited> 
        <goals> 
         <goal>aggregate-jar</goal> 
        </goals> 
        <configuration> 
         <sourcepath> 
         ../something-api: 
         ../something-impl: 
         ../something-else-api: 
         ../something-else-impl: 
         </sourcepath> 
         <destDir>all</destDir> 
         <finalName>all</finalName> 
         <show>protected</show> 
         <detectLinks>true</detectLinks> 
        </configuration> 
       </execution> 
       <execution> 
        <id>aggregated-documentation-interface</id> 
        <phase>package</phase> 
        <inherited>false</inherited> 
        <goals> 
         <goal>aggregate-jar</goal> 
        </goals> 
        <configuration> 
         <sourcepath> 
         ../something-api: 
         ../something-else-api: 
         </sourcepath> 
         <destDir>interface</destDir> 
         <finalName>interface</finalName> 
         <show>protected</show> 
         <detectLinks>true</detectLinks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

回答

0

也許你在<configuration>有缺失的一個重要組成部分,即<classifier>

What is the purpose of Classifier tag in maven?

所以你的執行階段應只是工作細

<configuration> 
    <classifier>aggregated-documentation-all</classifier> 
    .... 
</configuration> 
... 
... 
<configuration> 
    <classifier>aggregated-documentation-interface</classifier> 
    .... 
</configuration> 

來源 - Ant to Maven - multiple build targets從@Tim奧布萊恩

有用的見解回答 - Maven JAR plugin

免責聲明 - Why-you-shouldnt?

EDIT1 -從意見進一步注意到,您的POM是一個聚合的pom.xml在這種情況下建議你用 -

<inherited>true</inherited> 

,並保持對不同executions指定不同<destDir>確認看不同的輸出點。


EDIT2 - 澄清更多使用的例子。我在這裏工作的是編輯父模塊pom.xml 以包含下面的內容。執行mvn clean install使用在執行指定不同的配置這種變化產生兩種不同/target文件夾 -

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <version>2.10.4</version> 
      <configuration> 
       <additionalparam>-Xdoclint:none</additionalparam> 
      </configuration> 
      <executions> 
       <execution> 
        <!--This shall generate the package inside the /target folder of parent module--> 
        <id>first</id> 
        <phase>package</phase> 
        <inherited>true</inherited> 
        <goals> 
         <goal>aggregate-jar</goal> 
        </goals> 
        <configuration> 
         <classifier>first</classifier> 
         <show>protected</show> 
         <detectLinks>true</detectLinks> 
        </configuration> 
       </execution> 
       <execution> 
        <!--This shall generate the /target on project.basedir of your project--> 
        <id>second</id> 
        <phase>package</phase> 
        <inherited>true</inherited> 
        <goals> 
         <goal>aggregate-jar</goal> 
        </goals> 
        <configuration> 
         <destDir>${project.basedir}</destDir> 
         <classifier>second</classifier> 
         <!--Notice the package in this /target would not include following packages--> 
         <excludePackageNames>com.xyz.in.my.project</excludePackageNames> 
         <finalName>second</finalName> 
         <show>protected</show> 
         <detectLinks>true</detectLinks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
+0

感謝回答,但是這似乎沒有什麼區別的。請注意,我的頂級pom是一個聚合pom。我在父pom中定義了javadoc插件,它是子模塊之一。所有其他子模塊都將其指定爲其父代。我在頂層運行了「mvn install」,並生成了「target/* - javadoc.jar」,它似乎具有所有類的javadoc。在分類器設置中,我看不到任何輸出中的任何影響。 –

+0

@大衛好吧,這個問題讀*母pom(這不是聚合POM)*。另外請注意,如果您將它用作聚合器POM,您可能需要指定' true ' – nullpointer

+0

我真的對您在這裏所說的內容感到困惑。我在原來的帖子中很清楚,我有一個聚合器pom和一個父pom,並且我的javadoc插件設置位於父pom中。頂部目錄中的POM是聚合器POM,其中一個子POM是父POM。 –

相關問題