# compileJava does not build incrementally

**URL:** <https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752>\
**Category:** Help/Discuss\
**Created:** [February 23, 2024, 10:14am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752 "2024-02-23T10:14:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CoolLoong](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/coolloong/32/10395_2.png) [@CoolLoong](https://discuss.gradle.org/u/CoolLoong)\
**Post date:** [February 23, 2024, 10:14am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752/1 "2024-02-23T10:14:18Z")

</div>

I was compiling my project and noticed that even if I change only one class file, e.g. Player.java, it will recompile the whole project.  
[Build Scan® | Gradle Cloud Services](https://scans.gradle.com/s/rqkhzu77tx5og) that the build cache is not hit, and I don’t understand the real mechanism of how that cache works.  
This is the build file of my project [PowerNukkitX/build.gradle.kts at master · PowerNukkitX/PowerNukkitX · GitHub](https://github.com/PowerNukkitX/PowerNukkitX/blob/master/build.gradle.kts)

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [February 23, 2024, 10:38am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752/2 "2024-02-23T10:38:10Z")

</div>

Of course the build cache will not be hit, that is only for full task outputs.  
So either you have the exact same inputs and can use the outputs of the task as a whole from cache, or the task needs to execute.

But Gradle does incremental Java compilation.  
So if you change one file, only that files and all files using it directly or transitively will get recompiled.  
For more info see: [The Java Plugin](https://docs.gradle.org/current/userguide/java_plugin.html#sec:incremental_compile)

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [February 23, 2024, 10:40am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752/3 "2024-02-23T10:40:17Z")

</div>

Oh, I see you use the bloody Lombok.  
As far as I remember the dirty hooking into the compiler also needs it to disable incremental Java compilation.  
So iirc, you indeed need to recompile everything always for any change as long as you use Lombok.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [February 23, 2024, 10:45am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752/4 "2024-02-23T10:45:18Z")

</div>

Hm, no, it should not any longer.  
[Lombok disables incremental compilation in gradle · Issue #1580 · projectlombok/lombok · GitHub](https://github.com/projectlombok/lombok/issues/1580) should be fixed since 1.16.22 and you are using 1.18.30

---

<div class="post-metadata">

**Author:** ![CoolLoong](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/coolloong/32/10395_2.png) [@CoolLoong](https://discuss.gradle.org/u/CoolLoong)\
**Post date:** [February 23, 2024, 10:45am UTC](https://discuss.gradle.org/t/compilejava-does-not-build-incrementally/47752/5 "2024-02-23T10:45:58Z")

</div>

I also dislike lombok very much, but it’s a damn legacy and I’ve decided to delombok completely
