# Incremental Java Compile has been very temperamental

**URL:** https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313
**Category:** Help/Discuss
**Created:** [August 23, 2018, 5:26pm UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313 "2018-08-23T17:26:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![arahman](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@arahman](https://discuss.gradle.org/u/arahman)
#### Post date: [August 23, 2018, 5:26pm UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313/1 "2018-08-23T17:26:23Z")

</div>

Hi,

I have a Spring Project with about 3500 files. 99% of the files are currently generated off a third party codegen library JOOQ. When I change in the remaining 1% of the files it sometimes does a full javaCompile and sometimes does incremental build - as if it has a mind of its own.

When it does a full compile for small code changes during the change -\> build -\> run cycle is it very disruptive as full build takes over 5 minutes. Every second or third recompile this happens.

I have this entry in **gradle.build** :  
tasks.withType(JavaCompile) {  
 //enable compilation in a separate daemon process  
 options.fork = true

//enable incremental compilation  
 options.incremental = true  
}

And this is what **gradle.properties** looks like:  
org.gradle.java.home=C:\Program Files\Java\jdk1.8.0\_181  
org.gradle.daemon=true  
org.gradle.parallel=true  
org.gradle.configureondemand=true  
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

How can this be fixed?

---

<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: [August 24, 2018, 7:21am UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313/2 "2018-08-24T07:21:13Z")

</div>

You’re probably changing a file with a public constant, which requires a full recompile because constants can be inlined anywhere, so our bytecode analysis can’t reliably detect who uses them. Avoid public constants and use static methods instead.

---

<div class="post-metadata">

### Author: ![arahman](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@arahman](https://discuss.gradle.org/u/arahman)
#### Post date: [August 29, 2018, 12:38pm UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313/3 "2018-08-29T12:38:39Z")

</div>

Setting up build caching in the gradle.properties file seems to have made it a lot better.

---

<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: [August 29, 2018, 12:43pm UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313/4 "2018-08-29T12:43:14Z")

</div>

Caching and incremental compile are completely unrelated. The only thing that caching would improve is if you go back and forth between branches a lot or you do changes and then undo them again. Caching doesn’t help with incremental changes.

---

<div class="post-metadata">

### Author: ![arahman](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@arahman](https://discuss.gradle.org/u/arahman)
#### Post date: [August 29, 2018, 1:19pm UTC](https://discuss.gradle.org/t/incremental-java-compile-has-been-very-temperamental/28313/5 "2018-08-29T13:19:36Z")

</div>

Ok, magically the issue stopped immediately after I updated the gradle.build file, unsure then of what it may have been.

Thanks for the feedback.
