dockerfile-gradle-build-without-cache-mount
Detects Java Dockerfiles that run Gradle build tasks without a visible BuildKit cache mount on the same instruction.
This rule looks for:
- a Docker build discovered from GitHub Actions
build.gradle,build.gradle.kts,settings.gradle, orsettings.gradle.ktsin the build contextRUN gradle build,RUN ./gradlew build,assemble,bootJar, orshadowJar- no
--mount=type=cacheon that Dockerfile instruction
Why it matters:
- Gradle builds reuse downloaded dependencies, plugin artifacts, and build cache data from Gradle user home.
- Without a BuildKit cache mount, Docker rebuilds can repeatedly pay those costs.
- Depot’s optimized Gradle Dockerfile mounts Gradle user home during the build step.
What to do:
- Add a BuildKit cache mount for Gradle user home.
- Keep
--build-cacheororg.gradle.caching=trueenabled when it fits the repository.
This rule intentionally does not require tests to be skipped or the daemon to be disabled, because those choices are repository policy dependent.