我想使用聚合目标为我的整个项目生成javadoc,但我还想为几个子项目生成javadoc jar。在我的父pom.xml中,我添加了以下pluginManagement以允许子项目轻松生成javadoc jar:
<project>
...
<build>
<pluginManagement>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
...
然后在需要javadoc jar的子项目中我添加了:
<project>
...
<build>
<plugins>
<plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
...
到目前为止一切顺利。现在我想使用聚合目标来获取一整套javadoc,所以我在父pom中添加了对javadoc插件的另一个引用:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
...
这会导致javadoc插件被拉入每个子项目,而不仅仅是需要它的少数几个子项目。似乎jar和聚合目标可以独立地工作,但是当它们一起使用时会引起问题。有人解决了这样的问题吗?
提前致谢!
答案 0 :(得分:1)
我通过做类似的事情来解决这个问题:Can I configure multiple plugin executions in pluginManagement, and choose from them in my child POM?基本上我为javadoc jar实例添加了一个id到两个执行和一个none的阶段。然后我将阶段重新包装回仅包含需要javadoc jar的子项目。这是父pom中的pluginManagement:
<project>
...
<build>
<pluginManagement>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>none</phase>
<goals>
<goal>jar</goal>
</goals>
...
然后在子项目pom中需要以下内容打开javadoc jar:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
...