本文翻譯自:Maven is not working in Java 8 when Javadoc tags are incomplete
Since I use Maven I have been able to build and install in my local repository projects that have incomplete Javadoc tags (for example, a missing parameter). 自從我使用Maven以來,我已經能夠在本地存儲庫中構建並安裝具有不完整Javadoc標記(例如,缺少參數)的項目。
However, since I migrated to Java 8 (1.8.0-ea-b90) Maven is absolutely strict about missing documentation tags and show me lots of Javadoc errors related to Javadoc problems when I try to build or install a project where the Javadoc is not "perfect". 但是,由於我遷移到Java 8(1.8.0-ea-b90),因此Maven對缺少文檔標籤的要求絕對嚴格,並在嘗試構建或安裝Javadoc不在其中的項目時向我展示許多與Javadoc問題有關的Javadoc錯誤。 “完善”。 Some of the projects I am trying to compile and install in my local repository are third party projects from which I do not have control. 我試圖編譯並安裝在本地存儲庫中的某些項目是我無法控制的第三方項目。 So the workaround of just fixing all the Javadocs in all these projects does not seem to be feasable in my scenario. 因此,在我的情況下,僅修復所有這些項目中的所有Javadocs的變通辦法似乎不可行。
This is a small part of the output I see when I execute mvn clean package install
in my project: 這是我在項目中執行mvn clean package install
時看到的輸出的一小部分:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.026s
[INFO] Finished at: Mon Apr 08 21:06:17 CEST 2013
[INFO] Final Memory: 27M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9:jar (attach-javadocs) on project jpc: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /Users/sergioc/Documents/workspaces/heal/jpc/src/main/java/org/jpc/engine/prolog/PrologDatabase.java:10: error: @param name not found
[ERROR] * @param terms the terms to assert
[ERROR] ^
[ERROR] /Users/sergioc/Documents/workspaces/heal/jpc/src/main/java/org/jpc/engine/prolog/PrologDatabase.java:11: warning: no description for @return
[ERROR] * @return
[ERROR] ^
The Javadoc Maven plugin is configured like this in my POM: 在我的POM中,Javadoc Maven插件的配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
As I said before, everything is working fine if I go back to Java 7. Maybe is this a bug related to Maven running in Java 8? 如前所述,如果我回到Java 7,一切都會正常進行,也許這是與Java 8中運行的Maven有關的bug? How could I make it work (ie, being able to build the Javadoc of the project and install its code in my local repository) with Java 8? 如何使它與Java 8一起工作(即,能夠構建項目的Javadoc並將其代碼安裝在本地存儲庫中)? I have tested with both Maven 3.0.3 and 3.0.5 in OSX. 我已經在OSX中使用Maven 3.0.3和3.0.5進行了測試。
UPDATE: 更新:
If I change my Javadoc plugin configuration with <failOnError>false</failOnError>
(thanks Martin): 如果我使用<failOnError>false</failOnError>
更改Javadoc插件配置(感謝Martin):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Then the project is installed in my local repository. 然後將項目安裝在我的本地存儲庫中。 However, the Javadoc JAR is still not generated. 但是,仍未生成Javadoc JAR。
A fragment of the output I see in the console with this new configuration is: 我在控制檯中看到的具有此新配置的輸出片段是:
[ERROR] MavenReportException: Error while creating archive: Exit code: 1 - /Users/....java:18: warning: no @param ... Command line was: /Library/Java/Home/bin/javadoc @options @packages [錯誤] MavenReportException:創建存檔時出錯:退出代碼:1-/Users/....java:18:警告:否@param ...命令行爲:/ Library / Java / Home / bin / javadoc @options @包裝
Refer to the generated Javadoc files in '/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs' dir. 請參考“ / Users / sergioc / Documents / workspaces / heal / minitoolbox / target / apidocs”目錄中生成的Javadoc文件。
at org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeJavadocCommandLine(AbstractJavadocMojo.java:5043) at org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeReport(AbstractJavadocMojo.java:1990) at org.apache.maven.plugin.javadoc.JavadocJar.execute(JavadocJar.java:181) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.Lifecyc 在org.apache.maven.plugin上org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeReport(AbstractJavadocMojo.java:1990)上org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeJavadocCommandLine(AbstractJavadocMojo.java:5043) org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)的.javadoc.JavadocJar.execute(JavadocJar.java:181)org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java :209),位於org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153),位於org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)。位於org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)的maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)位於org.apache.maven.lifecycle.internal.LifecycleStarter。在org.apache.maven.lifecycle.internal.Lifecyc上的singleThreadedBuild(LifecycleStarter.java:183) leStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:491) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) org.apache.maven上的leStarter.execute(LifecycleStarter.java:161).org.apache.maven上的DefaultMaven.doExecute(DefaultMaven.java:320)。org.apache.maven上的DefaultMaven.execute(DefaultMaven.java:156) .cli.MavenCli.execute(MavenCli.java:537)在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)在org.apache.maven.cli.MavenCli.main(MavenCli.java:141) )處sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法)處java.lang.reflect處sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)處sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)處在org.codehaus.plexus.classworlds.launcher.Launcher.launch上的Method.invoke(Method.java:491)在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java: 230)在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Any workaround about how to build the sources, install the project and generate the Javadoc JAR in one step as it was working with Java 7? 關於如何構建源代碼,安裝項目以及在與Java 7一起工作的一步中生成Javadoc JAR的任何變通辦法?
#1樓
參考:https://stackoom.com/question/14ejB/Javadoc標記不完整時-Maven無法在Java-中工作
#2樓
You could try setting the failOnError
property (see plugin documentation ) to false
: 您可以嘗試將failOnError
屬性(請參閱插件文檔 )設置爲false
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
</configuration>
</execution>
</executions>
</plugin>
As you can see from the docs, the default value is true
. 從文檔中可以看到,默認值爲true
。
#3樓
The best solution would be to fix the javadoc errors. 最好的解決方案是修復javadoc錯誤。 If for some reason that is not possible (ie: auto generated source code) then you can disable this check. 如果由於某種原因(例如:自動生成的源代碼)是不可能的,則可以禁用此檢查。
DocLint is a new feature in Java 8 , which is summarized as: DocLint是Java 8中的一項新功能,總結爲:
Provide a means to detect errors in Javadoc comments early in the development cycle and in a way that is easily linked back to the source code. 提供一種在開發週期的早期檢測Javadoc註釋中的錯誤的方法,並且可以輕鬆地將其鏈接回源代碼。
This is enabled by default, and will run a whole lot of checks before generating Javadocs. 默認情況下啓用此功能,並且在生成Javadocs之前將運行大量檢查。 You need to turn this off for Java 8 as specified in this thread . 您需要爲此線程中指定的Java 8關閉此功能 。 You'll have to add this to your maven configuration: 您必須將其添加到您的Maven配置中:
<profiles>
<profile>
<id>java8-doclint-disabled</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
For maven-javadoc-plugin 3.0.x: Replace 對於maven-javadoc-plugin 3.0.x:替換
<additionalparam>-Xdoclint:none</additionalparam>
with 與
<doclint>none</doclint>
#4樓
The easiest approach to get things working with both java 8 and java 7 is to use a profile in the build: 使Java 8和Java 7都能正常工作的最簡單方法是在構建中使用配置文件:
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
#5樓
Overriding maven-javadoc-plugin
configuration only, does not fix the problem with mvn site
(used eg during the release stage). 僅覆蓋maven-javadoc-plugin
配置不能解決mvn site
的問題(例如,在發佈階段使用)。 Here's what I had to do: 這是我必須要做的:
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</profile>
#6樓
Here is the most concise way I am aware of to ignore doclint warnings regardless of java version used. 這是我知道的最簡潔的方法,無論使用什麼Java版本,都可以忽略doclint警告。 There is no need to duplicate plugin configuration in multiple profiles with slight modifications. 只需稍作修改,就無需在多個配置文件中重複插件配置。
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id> <!-- The actual id should be apparent from maven output -->
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Tested on oracle/open jdk 6, 7, 8 and 11. 在oracle / open jdk 6、7、8和11上測試