当 Javadoc 标签不完整时,Maven 在 Java 8 中不起作用

2022-08-31 04:55:13

自从我使用Maven以来,我已经能够在具有不完整的Javadoc标签(例如,缺少参数)的本地存储库项目中构建和安装。

但是,由于我迁移到Java 8(1.8.0-ea-b90),Maven对缺少文档标签绝对严格,当我尝试构建或安装Javadoc不“完美”的项目时,它会向我显示许多与Javadoc问题相关的Javadoc错误。我试图在本地存储库中编译和安装的一些项目是我无法控制的第三方项目。因此,在我的场景中,仅修复所有这些项目中的所有Javadocs的解决方法似乎并不可行。

这是我在项目中执行时看到的输出的一小部分: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] ^

Javadoc Maven插件在我的POM中是这样配置的:

<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,一切都会正常。也许这是一个与在Java 8中运行的Maven相关的错误?我如何使用Java 8使其工作(即能够构建项目的Javadoc并将其代码安装到我的本地存储库中)?我已经在OSX中使用了Maven 3.0.3和3.0.5进行测试。

更新:

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

<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 仍未生成。

我在控制台中看到的具有此新配置的输出片段是:

[错误]MavenReportException: 创建存档时出错: 退出代码: 1 - /Users/....java:18: 警告: 没有@param ...命令行是:/Library/Java/Home/bin/javadoc @options @packages

请参阅'/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs'dir中生成的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) atorg.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) atorg.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) atorg.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)

关于如何构建源代码,安装项目和生成Javadoc JAR的任何解决方法,因为它正在使用Java 7时一步?


答案 1

最好的解决方案是修复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>

<doclint>none</doclint>

答案 2

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

推荐