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

**URL:** <https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635>\
**Category:** Help/Discuss\
**Tags:** incremental\
**Created:** [September 17, 2018, 7:10am UTC](https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635 "2018-09-17T07:10:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adithyank](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@adithyank](https://discuss.gradle.org/u/adithyank)\
**Post date:** [September 17, 2018, 7:10am UTC](https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635/1 "2018-09-17T07:10:20Z")

</div>

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
}

```

}

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [September 17, 2018, 9:58am UTC](https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635/2 "2018-09-17T09:58:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adithyank](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@adithyank](https://discuss.gradle.org/u/adithyank)\
**Post date:** [September 17, 2018, 10:20am UTC](https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635/3 "2018-09-17T10:20:55Z")

</div>

> 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 !

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [September 17, 2018, 9:29pm UTC](https://discuss.gradle.org/t/incremental-compilation-does-not-work-in-compilegroovy-for-java-and-groovy-source-files/28635/4 "2018-09-17T21:29:53Z")

</div>

> [@adithyank](#):
>
> No. It is not failing with any error. Just for FYI

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.

> [@adithyank](#):
>
> Is there any way to configure compileGroovy to make use of that facility.

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.
