我發現了一個解決方案,我的自我。這有點破解,但它確實對我有用。我選擇了我的第一個想法:
獲取artifacts(sources.jar)我想包括,解壓縮它們,並以某種方式將javadoc插件指向源目錄。
這個方案有四個部分型動物,我會在後面詳細解釋:
- 產生我想包括
- 所有工件sources.jars解開那些sources.jars
- 通過將javadoc插件指向解壓縮的源生成Javadoc
- 將生成的apidoc打包到zip文件中
現在更詳細:
1.生成我想包括
要生成,你必須使用maven-源,插件sources.jars所有工件sources.jars如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>bundle-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
您必須在您希望包含在您的apidocs中的每個項目/模塊/工件中執行此操作。
2.解壓那些sources.jars
在你的pom.xml用來生成你必須添加以下插件解壓sources.jar文件的javadoc。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-artifact-sources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId><!-- your artifact here --></artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/unpack_sources</outputDirectory>
</configuration>
</execution>
<!-- add more unpack-executions here -->
</executions>
</plugin>
您可以根據需要添加儘可能多的解包執行塊。
3.指向Javadoc的插件解壓源
現在棘手的生成Javadoc。讓javadoc插件知道在哪裏查找源文件。導入的定義是<sourcepath>
定義。在本節中,我們定義,我們已在步驟2中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<sourcepath>${project.build.directory}/unpack_sources</sourcepath>
</configuration>
<executions>
<execution>
<goals>
<goal>javadoc</goal>
</goals>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
當你調用mvn clean install
在這一點上,你將最終獲得您的target
文件夾內的文件夾site
解壓的源文件夾。在這個網站文件夾中,你會發現你的apidocs。但是爲了讓這種構建能夠讓所有閃亮和我們想要將apidocs組裝成一個zip檔案。
四,包裝在一個zip文件
產生的apidocs要組裝您必須使用maven-assembly-plugin
和額外的組件文件的文檔。 首先插件,確定指標的POM內:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>docs-assembly</id>
<phase>package</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assemble.xml</descriptor>
</descriptors>
</configuration>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
assemble.xml:
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>${project.build.finalName}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>target/site/apidocs</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>