Markdown Edit

Gradle Build System

Gradle is an open-source build automation tool primarily used for JVM projects (Java, Kotlin, Scala) with declarative Kotlin DSL (build.gradle.kts) and Groovy DSL support, incremental compilation, build caching, and configuration caching.

Caching Architecture

Gradle splits its persistent state across two directory trees:

  1. Global User Home (~/.gradle/):
  2. Project-Local Directory (<project>/.gradle/):

Troubleshooting: Deleting ~/.gradle/caches/ While a Daemon is Running

Manually deleting $HOME/.gradle/caches/ while a background Gradle Daemon is still running — or while <project>/.gradle/configuration-cache/ retains serialized state — causes subsequent builds to fail with ClassNotFoundException or PluginInstantiationException even after Gradle re-downloads the dependency JARs.

Error Symptoms

  1. Missing Plugin Implementation Class (PluginInstantiationException):
* What went wrong:
An exception occurred applying plugin request [id: 'org.graalvm.buildtools.native', version: '1.1.12']
> Could not find implementation class 'org.graalvm.buildtools.gradle.NativeImagePlugin' for plugin 'org.graalvm.buildtools.native' specified in jar:file:/home/.../.gradle/caches/modules-2/files-2.1/org.graalvm.buildtools/native-gradle-plugin/1.1.12/.../native-gradle-plugin-1.1.12.jar!/META-INF/gradle-plugins/org.graalvm.buildtools.native.properties.
  1. Missing Compiled Buildscript Task Class in VisitableURLClassLoader:
* What went wrong:
Error while reading task graph
> Exception while loading configuration for :common: Class 'Build_gradle$GenerateVersionTask' not found in class loader 'VisitableURLClassLoader(...)' of type 'org.gradle.internal.classloader.VisitableURLClassLoader'.

Root Cause

Resolution

Whenever clearing ~/.gradle/caches/, always stop all running Gradle Daemons and remove the project-local .gradle/ directory (especially .gradle/configuration-cache/):

gradle --stop
rm -rf ~/.gradle/caches/ .gradle/

If using Nix and direnv:

direnv exec . gradle --stop
rm -rf ~/.gradle/caches/ .gradle/