Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

However, in my build, subsequent executions of a gradle task, with no changes in between, this incremental feature is not working. compileJava, jar, etc are executing with every build rather than only when changes have been made.

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:

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:

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?

like image 750
StormeHawke Avatar asked Oct 29 '13 18:10

StormeHawke


2 Answers

When you run with --info, Gradle will tell you why the task isn't up-to-date.

like image 161
Peter Niederwieser Avatar answered Oct 31 '22 09:10

Peter Niederwieser


Two things you need to do

  1. Check if your gradle version is above 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

like image 26
codebee Avatar answered Oct 31 '22 09:10

codebee