【问题标题】:How to make maven-javadoc-plugin generate multiple jars?如何让 maven-javadoc-plugin 生成多个 jar?
【发布时间】:2016-12-02 23:55:52
【问题描述】:

我有一个多模块项目。在父 pom(不是聚合器 POM)中,我使用的是maven-javadoc-plugin。它有两次执行,都在package 阶段,一次用于jar 目标,一次用于aggregate-jar 目标。

这很好地生成了构建中所有(非测试)类的完整聚合 Javadoc jar。

我需要做的是生成 两个 Javadoc 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>

【问题讨论】:

    标签: maven javadoc maven-javadoc-plugin


    【解决方案1】:

    您可能在&lt;configuration&gt;&lt;classifier&gt; 中遗漏了一个重要部分

    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 O'Brien 的回答

    有用的见解 - Maven JAR plugin

    免责声明 - Why-you-shouldnt?

    Edit1 - 从 cmets 进一步注意到您的 pom 是一个聚合器 pom.xml 在这种情况下建议您使用 -

    <inherited>true</inherited>
    

    并且还要注意为不同的executions 指定不同的&lt;destDir&gt; 以确认查看不同的输出。


    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>
    

    【讨论】:

    • 感谢您的回复,但这似乎没有任何区别。请注意,我的顶级 pom 是一个聚合 pom。我在父 pom 中定义了 javadoc 插件,它是子模块之一。所有其他子模块都将其指定为其父 pom。我在顶层运行了“mvn install”,它生成了“target/*-javadoc.jar”,它似乎包含所有类的 javadoc。我在任何输出中都没有看到分类器设置有任何影响的迹象。
    • @David 好的,问题是 parent pom(它不是聚合器 POM)。另请注意,如果您将其用作聚合器 POM,您可能需要指定 &lt;inherited&gt;true&lt;inherited&gt;
    • 我真的被你在这里说的弄糊涂了。我在原始帖子中很清楚我有一个聚合器 pom 和一个父 pom,我的 javadoc 插件设置在父 pom 中。顶层目录中的POM是聚合器pom,其中一个子pom是父pom。
    • @DavidM.Karr 我已经用一个在多模块分层项目中对我有用的示例更新了答案。
    • 这仍然不起作用。我将对此尝试不同的策略,以下显示了我目前对这个想法的问题:stackoverflow.com/questions/41002637/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 2016-07-01
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多