Maven 3:为定义的工件生成 Javadoc
我只想从专用文档项目中为我的项目的某些工件生成 javadoc。
这意味着我想要一个名为“docs”的独立项目。在 docs/pom.xml 中,我想定义应包含在生成的 javadoc 中的工件。
到目前为止,我了解到我必须为我想要包含的项目生成一个单独的sources.jar。但我不知道如何从那里继续下去。
现在我只能想象两种方法:
获取我想要包含的工件(sources.jar),解压它们并以某种方式将Javadoc插件指向源目录。
将我感兴趣的工件定义为依赖项,并使用 javadoc-plugin 的“dependencySourceInclude”选项。但我不确定这是否是预期的用法。
有什么建议如何解决这个问题吗?
I want to generate javadocs only for certain artifacts of my project from within a dedicated docs-project.
That means that I would like to have an independent project called "docs" for example. In the docs/pom.xml I would like to define the artifacts that should be included in the generated javadocs.
So far I learned that I have to generate a separate sources.jar for the projects I want to include. But I can't figure out how to go on from there.
For now I can only imagine two approaches:
Get the artifacts (sources.jar) I want to include, unpack them and somehow point the Javadoc plugin to the source directory.
Define the artifacts I am interested as dependency and use the "dependencySourceInclude" option of the javadoc-plugin. But I am not sure if this is usage as intended.
Any suggestions how to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了解决方案。这有点麻烦,但对我来说确实有用。我选择遵循我的第一个想法:
该解决方案有四个不同的部分,稍后我将更详细地解释:
现在更详细:
1. 在我想要包含的所有工件中生成sources.jars
要生成sources.jars,您必须使用maven-sources-plugin,如下所示:
您必须在要包含的每个项目/模块/工件中执行此操作你的API文档。
2.解压这些sources.jars
在用于生成javadoc的pom.xml中,您必须添加以下插件来解压sources.jar文件。
您可以根据需要添加任意数量的解包执行块。
3.通过将 javadoc-plugin 指向解压的源代码来生成 Javadoc
现在是棘手的部分。让 javadoc-plugin 知道在哪里查找源文件。导入的定义是
定义。在本节中,我们定义在步骤 2 中解压源代码的文件夹。此时,当您调用
mvn clean install
时,您最终会在您的计算机中得到一个site
文件夹。目标
文件夹。在此站点文件夹中,您将找到您的 apidocs。但为了让这个构建变得光彩夺目,我们希望将 apidocs 组装成 zip 存档。4.将生成的 apidocs 打包在 zip 文件中
要组装文档,您必须使用
maven-assemble-plugin
和一个额外的程序集文件。首先是 pom 中的插件定义:
assemble.xml:
I have found a solution my self. It is a bit of a hack but it does work for me. I chose to go with my first idea:
This solution has four differents parts which I'll explain in more detail later:
Now in more detail:
1. Generate sources.jars in all artifacts I want to include
To generate sources.jars you have to use the maven-sources-plugin as follows:
You have to do this in every project/module/artifact you want to include in your apidocs.
2. Unpack those sources.jars
In you pom.xml you use to generate the javadocs you have to add the following plugins to unpack the sources.jar files.
You can add as many unpack-execution-blocks as you like.
3. Generate Javadoc by pointing the javadoc-plugin to the unpacked sources
Now the tricky part. Letting the javadoc-plugin know where to look for the source files. The imported definition is the
<sourcepath>
definition. In this section we define the folder where we have unpacked the sources in step 2.When you call
mvn clean install
at this point you will end up with asite
folder inside yourtarget
folder. In this site folder you'll find your apidocs. But to make this build all shiny and stuff we want to assemble the apidocs into a zip archive.4. Package the generated apidocs in a zip file
To assemble the docs you have to use the
maven-assembly-plugin
and a extra assembly-file.First the plugin-defintion inside your pom:
assemble.xml: