Incremental compilation does not work in compileGroovy for java and groovy source files

We are using groovy plugin to compile java and groovy files as we need Java classes in groovy and vice versa.

After we introduced this groovy plugin in to our build script, the incremental build is not working. It is compiling all the java and groovy files every time even though there is no change in it. Currently we are using Gradle 4.10.1. The behavior is same.

Am I missing something? Pls advice

Below will be our source set

sourceSets {
	main {
		java { srcDirs = [] }    // no source dirs for the java compiler
		groovy { srcDirs = ['src/main/java', 'src/main/groovy'] }  // compile everything in src/ with groovy
	}
}

The build script has below configurations for compileJava and compileGroovy tasks

compileJava {
    options.fork = true

    options.forkOptions.with {
        memoryMaximumSize = "2g"
    }

    if (BUILD_TYPE.equals("LOCAL"))
    {
        //println project.name + " : LOCAL BUILD. Hence switching-on incremental mode"
        options.incremental = true
    }
}

compileGroovy {
options.fork = true

options.forkOptions.with {
    memoryMaximumSize = "2g"
}

if (BUILD_TYPE.equals("LOCAL"))
{
    //println project.name + " : LOCAL BUILD. Hence switching-on incremental mode"
    options.incremental = true
}

}

The Groovy compiler is not incremental. There is no incremental option on the task, so the snippet above should fail with an error. Also, configuring the javaCompile task has no effect when you’re compiling everything with Groovy.

The Groovy compiler is not incremental

Ok. Fine. Is there any way to reduce the compilation time? compileJava of ‘java’ plugin has this facility. Is there any way to configure compileGroovy to make use of that facility. Because, in our multi project build, the overall time taken has increased after introducing groovy? We need this cross compilation support also as we have both java and groovy sources

There is no incremental option on the task, so the snippet above should fail with an error.

No. It is not failing with any error. Just for FYI

Also, configuring the javaCompile task has no effect when you’re compiling everything with Groovy.

I had this doubt. Ok. Thanks for clarifying !

Then the BUILD_TYPE variable is not set to LOCAL in your snippet above. There is no incremental property on the GroovyCompile task. Trying to call it will result in an error.

No. If you want optimum build speed, don’t use Groovy. Or minimize its use. And don’t put everything together, minimize the Java code that needs to compile together with Groovy and compile the rest as pure Java.