简体   繁体   English

增量Gradle Build没有说UP-TO-DATE

[英]Incremental Gradle Build not saying UP-TO-DATE

Gradle, being an incremental build system, is supposed to detect when no changes to source or outputs have been made, and skip tasks when appropriate to save on build time. 作为增量构建系统的Gradle应该检测何时没有对源或输出进行任何更改,并在适当时跳过任务以节省构建时间。

However, in my build, subsequent executions of a gradle task, with no changes in between, this incremental feature is not working. 但是,在我的构建中,后续执行gradle任务,两者之间没有任何变化,这个增量功能不起作用。 compileJava, jar, etc are executing with every build rather than only when changes have been made. compileJava,jar等正在执行每个构建,而不仅仅是在进行了更改时。

Our build is pretty complex (switching to gradle from a very old, very messy ant build), so I'm just going to show a small snippet: 我们的构建非常复杂(从一个非常古老,非常凌乱的ant build转换为gradle),所以我只是展示一个小片段:

buildDir = 'build-server'
jar {
    sourceSets.main.java.srcDirs = ['src', 
                '../otherProject/src']

    sourceSets.main.java {

        include 'com/ourCompany/pkgone/allocation/**'
        include 'com/ourCompany/pkgone/authenticationmngr/**'
                      ...

        //Excludes from all VOBs
        exclude 'com/ourCompany/pkgtwo/polling/**'
    }

    sourceSets.main.resources.srcDirs = ['cotsConfig/ejbconfig']
    sourceSets.main.resources {
        include 'META-INF/**'
    }

}

dependencies {
    compile project(':common')
}

Running gradle jar on this project twice in a row results in the following output: 连续两次在此项目上运行gradle jar产生以下输出:

P:\Project>gradlew jar
:common:compileJava
:common:processResources UP-TO-DATE
:common:classes
:common:jar
:clnt:compileJava
:clnt:processResources UP-TO-DATE
:clnt:classes
:clnt:jar

BUILD SUCCESSFUL

Total time: 1 mins 46.802 secs
P:\Project>gradlew jar
:common:compileJava
:common:processResources UP-TO-DATE
:common:classes
:common:jar
:clnt:compileJava
:clnt:processResources UP-TO-DATE
:clnt:classes
:clnt:jar

BUILD SUCCESSFUL

My question is, what might I be doing that would prevent the up-to-date detection to not work properly? 我的问题是,我可以做些什么来阻止最新的检测无法正常工作? Could it be related to my complicated build path? 它可能与我复杂的构建路径有关吗?

当您使用--info运行时,Gradle会告诉您为什么任务不是最新的。

Two things you need to do 你需要做的两件事

  1. Check if your gradle version is above 2.1 检查您的gradle版本是否高于2.1
  2. There is a way setting incremental build: 有一种方法可以设置增量构建:

    tasks.withType(JavaCompile) { options.incremental = true // one flag, and things will get MUCH faster }

Reference is here: https://blog.gradle.org/incremental-compiler-avoidance 参考文献: https//blog.gradle.org/incremental-compiler-avoidance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM