Java8环境下的Maven javadoc插件的配置

问题

用maven在mvn clean package时,出现新的问题:生成javadoc出现异常,导致打包失败。

1
2
3
4
5
6
ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:jar (default) on project ticket-business: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /Users/nali/Documents/workspace/ticket/ticket-business/src/main/java/com/ximalaya/ticket/business/dao/ticket/TicketProductMapper.java:13: 错误: 未知标记: mbg.generated
[ERROR] * @mbg.generated Wed Mar 01 20:02:30 CST 2017
[ERROR] ^
[ERROR] /Users/nali/Documents/workspace/ticket/ticket-business/src/main/java/com/ximalaya/ticket/business/dao/ticket/TicketProductMapper.java:15: 警告: example没有 @param
[ERROR] long countByExample(TicketProductExample example);

配置

javadoc的插件pom.xml配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>javadoc</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>

排查

回退java版本到java7, 结果如下:

1
[WARNING] /Users/nali/Documents/workspace/ticket/ticket-business/src/main/java/com/ximalaya/ticket/business/model/TicketUser.java:172: 警告 - @mbg.generated是未知标记。

可以发现在java7中是可以通过的,而在java8中则会报错。

应该是java8加了对javadoc的新的特性,查看Java8的特性列表吧。果然,Java8添加了一个Javadoc注释内容检查的特性DocLint

DocLint提供了一种方法来检测Javadoc的注释中的错误,希望能够在开发周期的早期和容易链接回源代码的方式。

解决

1) 忽略注释错误

如果想忽略DocLint的使用,可以在maven-javadoc-plugin的配置中加上对DocLint的忽略。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>javadoc</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>

或者在控制台输出:

1
mvn clean install -Dadditionalparam=-Xdoclint:none

2) 跳过javadoc生成

控制台输出:

1
mvn clean install -Dmaven.javadoc.skip=true

参考:

https://tonydeng.github.io/2015/10/21/maven-Javadoc-plugin-in-java8-exception-resolution/

http://openjdk.java.net/jeps/172

热评文章