compileDebugJava - 不是增量的。无法推断源目录

compileDebugJava - is not incremental. Unable to infer the source directories

自 Gradle 2.1 起,现在支持 Java 源代码的增量编译 check this

我使用下面的代码片段来启用它

afterEvaluate {

    android.applicationVariants.each { variant ->
        variant.javaCompile.options.incremental = true
    }
}

但是我收到了以下警告消息,

:App:compileDebugJava - is not incremental. Unable to infer the source directories.

请建议我应该怎么做才能摆脱它

是的,Android 构建插件存在问题,请阅读此处:

We use custom sourceset so this is unlikely to be fixed until we can stop using them.

http://code.google.com/p/android/issues/detail?id=82411 并在此处提到

https://discuss.gradle.org/t/faster-incremental-builds/552/10

固定后,将此用于Android,在allProjects中添加:

allProjects {
    tasks.withType(JavaCompile) {
        configure(options) {
            incremental = true
        }
    }
}

如果你看到这个,你必须先构建你的项目:

compileDebugJava - is not incremental (e.g. outputs have changed, no previous execution, etc.).

如果你看到这个,根据 isse(参见 link)使用了错误的 sourceSets

compileDebugJava - is not incremental. Unable to infer the source directories.

来自他们 Java 项目的示例:

apply plugin: 'java'
compileJava {
    //enable compilation in a separate daemon process
    options.fork = true

    //enable incremental compilation
    options.incremental = true
}

来源: http://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html

我在使用 react-native 插件包时遇到了这样的问题。我 运行 react-native link 似乎已经解决了这个问题。