Skip to content

fix: use configureEach instead of all for JavaCompile tasks#852

Open
tinder-ryantrontz wants to merge 1 commit intosourcegraph:mainfrom
tinder-ryantrontz:fix/gradle-lazy-sourceset-javacompiler-finalized
Open

fix: use configureEach instead of all for JavaCompile tasks#852
tinder-ryantrontz wants to merge 1 commit intosourcegraph:mainfrom
tinder-ryantrontz:fix/gradle-lazy-sourceset-javacompiler-finalized

Conversation

@tinder-ryantrontz
Copy link

Problem

scip-java index crashes on Gradle 8.12.1 projects that define custom source sets (e.g. intTest) with a Java toolchain:

Caused by: java.lang.IllegalStateException:
  The value for task ':accountintegrity-models:compileIntTestJava'
  property 'javaCompiler' is final and cannot be changed any further.

  at org.gradle.api.plugins.JavaBasePlugin.lambda$createCompileJavaTask$6(JavaBasePlugin.java:229)

Root Cause

SemanticdbGradlePlugin uses the eager .withType(JavaCompile).all {} API inside afterEvaluate. This forces immediate realization of lazily-registered JavaCompile tasks. During realization, the plugin reads javaCompiler via .getOrNull(), which triggers Gradle's finalizeValueOnRead — locking the property before JavaBasePlugin can set its convention().

Fix

Replace .all {} with .configureEach {} (line 107 of SemanticdbGradlePlugin.scala). This defers the configuration action until Gradle has fully initialized each task.

Note: the Scala plugin path on line 222 already uses .configureEach {} correctly.

Verification

  • New test lazy-sourceset-with-toolchain reproduces the scenario (custom intTest source set + toolchain)
  • Full Gradle_8_BuildToolSuite passes (16/16, 1 skipped for JDK version)
  • Tested the built binary against a production Gradle 8.12.1 monorepo (40+ modules) — BUILD SUCCESSFUL, index.scip generated

The eager .all {} API forces realization of lazily-registered
JavaCompile tasks during afterEvaluate. When a project defines custom
source sets (e.g. intTest) with a Java toolchain, Gradle finalizes
the javaCompiler property during task realization — before
JavaBasePlugin.createCompileJavaTask finishes setting its convention.
This causes: 'property javaCompiler is final and cannot be changed'.

Replacing .all {} with .configureEach {} defers the configuration
action until Gradle has fully initialized each task.

Amp-Thread-ID: https://ampcode.com/threads/T-019cbfff-d981-727b-9564-00e5705dbcec
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant