当 Javadoc 标签不完整时,Maven 在 Java 8 中不起作用 [英] Maven is not working in Java 8 when Javadoc tags are incomplete

查看:34
本文介绍了当 Javadoc 标签不完整时,Maven 在 Java 8 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是,自从我迁移到 Java 8 (1.8.0-ea-b90) 后,Maven 对缺少文档标签绝对严格,并且当我尝试构建或安装一个Javadoc 并不完美".我试图在本地存储库中编译和安装的一些项目是我无法控制的第三方项目.因此,在我的场景中,仅修复所有这些项目中的所有 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 clean package install 时看到的输出的一小部分:

This is a small part of the output I see when I execute mvn clean package install in my project:

[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 中是这样配置的:

The Javadoc Maven plugin is configured like this in my 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 进行了测试.

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? How could I make it work (i.e., being able to build the Javadoc of the project and install its code in my local repository) with Java 8? I have tested with both Maven 3.0.3 and 3.0.5 in OSX.

更新:

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

If I change my Javadoc plugin configuration with <failOnError>false</failOnError> (thanks 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>

然后项目就安装在了我的本地仓库中.但是,Javadoc JAR 仍未生成.

Then the project is installed in my local repository. However, the Javadoc JAR is still not generated.

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

A fragment of the output I see in the console with this new configuration is:

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

[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

参考生成的Javadoc文件'/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs'目录.

Refer to the generated Javadoc files in '/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs' dir.

在org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeJavadocCommandLine(AbstractJavadocMojo.java:5043)在org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeReport(AbstractJavadocMojo.java:1990)在org.apache.maven.plugin.javadoc.JavadocJar.execute(JavadocJar.java:181)在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)在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:84)在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)在org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)在 org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 在org.apache.maven.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(Native Method) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.lang.reflect.Method.invoke(Method.java:491) 在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)在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)

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 的任何解决方法?

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?

推荐答案

最好的解决方案是修复 javadoc 错误.如果由于某种原因无法实现(即:自动生成的源代码),那么您可以禁用此检查.

The best solution would be to fix the javadoc errors. If for some reason that is not possible (ie: auto generated source code) then you can disable this check.

DocLint 是 Java 8 的一个新特性,总结如下:

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

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 之前运行大量检查.您需要按照指定为 Java 8 关闭此功能 在这个线程.您必须将此添加到您的 Maven 配置中:

This is enabled by default, and will run a whole lot of checks before generating Javadocs. You need to turn this off for Java 8 as specified in this thread. You'll have to add this to your maven configuration:

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

这篇关于当 Javadoc 标签不完整时,Maven 在 Java 8 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆