由于我使用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". 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.

这是我在我的项目中执行mvn清洁包安装时看到的输出的一小部分:

[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] ^

在我的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>

正如我之前所说,如果我回到Java 7,一切都可以正常工作。 也许这是一个与Maven在Java 8中运行有关的错误? 我如何使用Java 8使其工作(即,能够构建项目的Javadoc并将其代码安装在我的本地存储库中)? 我已经在OSX中用Maven 3.0.3和3.0.5进行了测试。

更新:

如果我用<failOnError>false</failOnError>(谢谢Martin)更改我的Javadoc插件配置:

<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>

然后将项目安装到本地存储库中。但是,仍然没有生成Javadoc JAR。

我在控制台中看到的这个新配置的输出片段是:

[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 Refer to the generated Javadoc files in '/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs' dir. 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.LifecycleStarter.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)

在使用Java 7时,是否有关于如何在一个步骤中构建源代码、安装项目和生成Javadoc JAR的解决方案?


当前回答

最好的解决方案是修复javadoc错误。如果出于某种原因,这是不可能的(即:自动生成的源代码),那么你可以禁用这个检查。

DocLint是Java 8中的一个新特性,可以概括为:

提供一种在Javadoc注释的早期检测错误的方法 开发周期,并以一种容易链接回 源代码。

这在默认情况下是启用的,在生成Javadocs之前会运行大量的检查。您需要关闭此线程中指定的Java 8的此功能。您必须将此添加到您的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>

对于maven-javadoc-plugin 3.0.0+: 取代

<additionalparam>-Xdoclint:none</additionalparam>

with

<doclint>none</doclint>

其他回答

在我的例子中,我使用的是父pom(不确定这是真正的原因,因为我在争分秒秒地工作),maven 2。由于某些原因,上面的解决方案不起作用,所以我添加了以下配置文件,并管理它使其运行:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>myapp</artifactId>
    <packaging>war</packaging>
    <name>myapp</name>
    <version>0.0.1-SNAPSHOT</version>
    <description>My App</description>
    <parent>
        <groupId>com.mycompany</groupId>
        <artifactId>parent-artifact</artifactId>
        <version>0.0.1</version>
    </parent>

    <profiles>
        <profile>
            <id>doclint-java6-disable</id>
            <activation>
                <jdk>[1.6,)</jdk>
            </activation>
            <properties>
                <additionalparam>--allow-script-in-comments</additionalparam>
            </properties>
        </profile>
    </profiles>
</project>

我不确定这是否会有所帮助,但即使是我也在最近使用oozie-4.2.0版本时遇到了完全相同的问题。读完上面的答案后,我刚刚通过命令行添加了maven选项,它对我有用。所以,在这里分享一下。

我使用的是java 1.8.0_77,没有尝试过java 1.7

bin/mkdistro.sh -DskipTests -Dmaven. opts .opts='-Xdoclint:-html'

下面的配置很适合我

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                <failOnError>false</failOnError>
            </configuration>
        </plugin>

添加以下

JAVA_TOOL_OPTIONS=-DadditionalJOption=-Xdoclint:none

詹金斯的工作:

配置>构建环境>向构建过程注入环境变量>属性内容

通过Jenkins Maven解决了我的代码构建问题:-)

添加到pom文件的全局属性部分:

<project>
    ...
    <properties>
        <additionalparam>-Xdoclint:none</additionalparam>
    </properties>

在其他答案中提供的通用解决方案(在插件部分中添加该属性)由于某种原因无法工作。只有全局设置,我才能成功构建javadoc jar。