java 在 Gradle 中禁用所有 JavaDoc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34874175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:29:13  来源:igfitidea点击:

Disable all JavaDoc in Gradle

javagradlejavadocbuild.gradle

提问by Peter

General Update,after some research
I want to build my project running gradle 2.0with gradle buildin the console I get stuck at the JavaDoc generation. I'm using Java 8, precisly jdk1.8.0_66and jre1.8.0_66. Now when I want to build my project typing gradle buildin my powershell I get this error:

一般更新,经过一些研究,
我想构建在控制台中运行的项目gradle 2.0gradle build我陷入了 JavaDoc 生成。我使用Java 8,precislyjdk1.8.0_66jre1.8.0_66。现在,当我想gradle build在我的 powershell 中输入构建我的项目时,我收到此错误:

5 errors
10 warnings
:my-subproject1:javadoc FAILED
    FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':my-subproject1:javadoc'.
> Javadoc generation failed.

One sample error and one sample warning:

一个示例错误和一个示例警告:

C:\some\long\path\MyClass.java:37: error: @param name not found
         * @param appCode
                  ^
C:\some\long\path\MyOtherClass.java:37: warning: no description for @param
         * @param appCode

If I disable one of my subprojects using tasks.findByPath(":my-subproject:javadoc").enabled = falsein my build.gradlefile I get the same error for the next subproject.
Research has shown that I'm not alone with my problem; Java 8 seems to be really strict with the JavaDoc. This is due to the new doclint for Javadoc. Found on this site. It also provides a solution for Maven and Gradle. But for me it doesn't work, another answer I gotdoesn't work either. My attempts to solve it look like this right now in my build.gradlefor this subproject:

如果我tasks.findByPath(":my-subproject:javadoc").enabled = false在我的build.gradle文件中禁用了我的一个子项目,我会在下一个子项目中得到同样的错误。
研究表明,我的问题并不孤单。Java 8 似乎对 JavaDoc 非常严格。这是由于新的doclint for Javadoc. 在这个网站上找到。它还为 Maven 和 Gradle 提供了解决方案。但对我来说它不起作用,我得到的另一个答案也不起作用。我现在在build.gradle这个子项目中解决它的尝试看起来像这样:

//Solution by the second link
allprojects {
    tasks.withType(Javadoc).all { enabled = false }
}
//Solution by the first link
if (JavaVersion.current().isJava8Compatible()) {
    allprojects {
        tasks.withType(Javadoc) {
            options.addStringOption('Xdoclint:none', '-quiet')
        }
    }
}


dependencies{
    compile project(':my-subproject1')
    compile project(':my-subproject2')
    compile project(':my-subproject3')
}

Does anybody know how to solve this issue or is there another workaround?

有谁知道如何解决这个问题,或者有其他解决方法吗?

Edit:

编辑:

C:. | Root
├───build.gradle
│   └───2.0
│       └───taskArtifacts
├───buildSrc
│   ├───.gradle
│   │   ├───2.0
│   │   │   └───taskArtifacts
│   │   └───noVersion
│   │       └───buildSrc
│   ├───build
│   │   ├───classes
│   │   │   └───main
│   │   ├───dependency-cache
│   │   ├───libs
│   │   └───tmp
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───custom
│                       └───gradle
│                           └───util
├───my-subproject1
├───my-subproject2
├───my-subproject3
│   ├───my-sub-subproject
│   ├───my-current-directory | Magic happens here
│   │   ├───some.package.identifier
│   │   │   ├───.clover
│   │   │   ├───.settings
│   │   │   ├───bin
│   │   │   │   └───package
│   │   │   │       └───subpackage
│   │   │   └───buil.gradle | This should build my subproject

Solution:Put it in the root build.gradlefile.

解决方法:放在根build.gradle文件中。

回答by Stanislav

If you have a root project build script, then you can disable all the subprojects's tasks by it's type. In your case, by type Javadoc, like:

如果您有一个根项目构建脚本,那么您可以根据其类型禁用所有子项目的任务。在您的情况下,按 type Javadoc,例如:

subprojects {
    tasks.withType(Javadoc).all { enabled = false }
}

回答by jgibson

I ran into this as well and after digging through Gradle's source code I found a solution that works in Gradle 2.9.

我也遇到了这个问题,在挖掘了 Gradle 的源代码后,我找到了一个适用于 Gradle 2.9 的解决方案。

Instead of options.addStringOption('Xdoclint:none', '-quiet')try options.addBooleanOption('Xdoclint:none', true). That should properly pass the -Xdoclint:noneoption to the underlying javadoc invocation and ignore the errors while still producing Javadoc output. I did this directly in the javadoc task declaration, but it would probably work using the allprojectsmethod that you tried above.

而不是options.addStringOption('Xdoclint:none', '-quiet')尝试options.addBooleanOption('Xdoclint:none', true)。这应该正确地将-Xdoclint:none选项传递给底层 javadoc 调用并忽略错误,同时仍然生成 Javadoc 输出。我直接在 javadoc 任务声明中执行了此操作,但使用allprojects您在上面尝试过的方法可能会起作用。

回答by Asaf Pinhassi

This is how I disabled it - in my my build.gradle file I added:

这就是我禁用它的方式 - 在我的 build.gradle 文件中我添加了:

tasks.withType(Javadoc).all { enabled = false } // non ascii characters make it crash