javadoc maven
许多人都知道Maven源代码和Javadoc工件,但是不知道为什么要创建它们。 我绝对是在这个阵营中–我可以理解为什么人们想要此信息,但是由于需要手动导航Maven存储库,因此获取信息似乎相对效率较低。
然后我被线索棒击中。
这些工件由IDE而非人员使用。 如果您使用的是maven依赖项,那么IDE足够聪明,可以知道如何查找这些工件。 当您单步调试器中的代码时,将使用源工件-不再需要将源代码显式绑定到IDE中的库。 javadoc工件用于编辑器中的自动完成和上下文相关帮助。
这些都不是必需的-多年来我一直很高兴使用'vi'-但是当您大部分都知道自己需要什么但不确定细节时,它肯定会提高您的生产率。
源工件
源工件最容易创建。 添加一个将作为标准构建的一部分自动运行的插件,您已完成。 构建花费的时间稍长一些,但是您只需要创建几个目录的归档文件就不必担心了。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<!-- create source jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<!-- produce source artifact for project main sources -->
<goal>jar-no-fork</goal>
<!-- produce test source artifact for project test sources -->
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Javadoc工件
Javadoc工件要复杂一些,因为您可能希望同时创建一个对人类友好的网站。 根据我的经验,最大的问题是外部类是不透明的,因为创建必需的链接花费了很多精力。 Maven插件现在为我们解决了这个问题!
构建该工件需要花费大量时间,因此您可能不想每次都这样做。 有两种方法-明确指定Maven目标或将其绑定到自定义配置文件,例如'javadoc'。 以下配置使用自定义配置文件。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<profiles>
<!-- create javadoc -->
<profile>
<id>javadoc</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<detectLinks />
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
<dependencySourceInclude>com.invariantproperties.project.student:*</dependencySourceInclude>
</dependencySourceIncludes>
<!-- heavily used dependencies -->
<links>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://docs.oracle.com/javaee/6/api</link>
<link>http://docs.spring.io/spring/docs/current/javadoc-api/</link>
<link>http://docs.spring.io/spring-data/commons/docs/1.6.2.RELEASE/api/</link>
<link>http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/api/</link>
<link>http://docs.spring.io/spring-data/data-jpa/docs/1.4.3.RELEASE/api/</link>
<link>https://jersey.java.net/apidocs/1.17/jersey/</link>
<link>http://hamcrest.org/JavaHamcrest/javadoc/1.3/</link>
<link>http://eclipse.org/aspectj/doc/released/runtime-api/</link>
<link>http://eclipse.org/aspectj/doc/released/weaver-api</link>
<link>http://tapestry.apache.org/5.3.7/apidocs/</link>
</links>
</configuration>
<executions>
<execution>
<id>aggregate</id>
<!-- <phase>site</phase> -->
<phase>package</phase>
<goals>
<goal>aggregate</goal>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<reportSets>
<reportSet>
<id>non-aggregate</id>
<configuration>
<!-- Specific configuration for the non aggregate report -->
</configuration>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate</id>
<configuration>
<!-- Specific configuration for the aggregate report -->
</configuration>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
</project>
包信息.java
最后,每个软件包都应该具有package-info.java文件。 这将替换旧的package-info.html文件,但由于它允许使用类注释,因此是一个改进。 (由于它是无效的类名,因此不会被编译。)
我发现包含指向资源的链接非常有帮助,这些链接可以帮助我理解类的外观。 例如,“学生”项目中的元数据包包含指向我的博客文章,我认为有用的其他博客文章甚至适当的Oracle教程的链接。 在公司中,这些可能是指向Wiki页面的链接。
/**
* Classes that support JPA Criteria Queries for persistent entities.
*
* @see <a href="http://invariantproperties.com/2013/12/19/project-student-persistence-with-spring-data/">Project Student: Persistence with Spring Data</a>
* @see <a href="http://invariantproperties.com/2013/12/29/project-student-jpa-criteria-queries/">Project Student: JPA Criteria Queries</a>
* @see <a href="http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-four-jpa-criteria-queries/">Spring Data JPA Tutorial Part Four: JPA Criteria Queries</a> [www.petrikainulainen.net]
* @see <a href="http://docs.oracle.com/javaee/6/tutorial/doc/gjitv.html">JEE Tutorial</a>
*
* @author Bear Giles <bgiles@coyotesong.com>
*/
package com.invariantproperties.project.student.metamodel;
源代码
- 源代码位于https://github.com/beargiles/project-student [github]和http://beargiles.github.io/project-student/ [github页面]。
翻译自: https://www.javacodegeeks.com/2014/02/creating-maven-source-and-javadoc-artifacts.html
javadoc maven