Skip to content

Compile GSP pages with the Java the project asked for - #16118

Open
codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/gsp-compile-java-toolchain-8.0.x
Open

Compile GSP pages with the Java the project asked for#16118
codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/gsp-compile-java-toolchain-8.0.x

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

Compiling GSP pages is forked, and a forked process runs whatever JVM it is given. Nothing gave it one, so it inherited the JVM running Gradle — meaning a project that declared a Java toolchain had its pages built by a different Java from everything else it built.

Nothing failed while building. The mismatch surfaced the first time a page was rendered:

UnsupportedClassVersionError: gsp_appindex_gsp has been compiled by a more recent version
of the Java Runtime (class file version 70.0), this version of the Java Runtime only
recognizes class file versions up to 69.0

compileGroovyPages now takes its launcher from the project's toolchain, so pages are compiled by the same Java as the rest of the project:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

What a page is compiled for follows what it is compiled by, unless the build sets targetCompatibility itself, which still wins.

The launcher is a @Nested input rather than an internal detail because the task is cacheable. The Java that did the compiling is part of what the result is, and without declaring it a cache entry produced by one Java was handed to a build asking for another — which survived a clean, so the usual workaround of pointing JAVA_HOME at the intended Java did not help either.

Limitations

A project that declares no toolchain is still built by the JVM running Gradle. That is what compiling pages fell back to before and remains the right answer when nothing else was asked for, but it means a build relying on JAVA_HOME alone is unchanged by this.

Compiling pages is forked, and a forked process runs whatever JVM it is given.
Nothing gave it one, so it inherited the JVM running Gradle. A project that
declared a toolchain had its pages built by a different Java from everything
else it built.

Nothing failed while building. The mismatch surfaced the first time a page was
rendered, as

    UnsupportedClassVersionError: gsp_appindex_gsp has been compiled by a more
    recent version of the Java Runtime (class file version 70.0), this version
    of the Java Runtime only recognizes class file versions up to 69.0

The launcher is nested rather than internal because the task is cacheable. The
Java that did the compiling is part of what the result is, and without saying so
an entry produced by one Java was handed to a build asking for another --
surviving a clean, which left the workaround of pointing JAVA_HOME at the
intended Java not working either.

What a page is compiled for now follows what it is compiled by, unless the build
set targetCompatibility for itself.

A project that asked for no toolchain is still built by the JVM running Gradle,
which is what pages fell back to before and remains the right answer when
nothing else was asked for.
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.4020%. Comparing base (a1e526f) to head (f813b48).
⚠️ Report is 19 commits behind head on 8.0.x.

Files with missing lines Patch % Lines
.../plugin/views/gsp/GroovyPageForkCompileTask.groovy 0.0000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16118        +/-   ##
==================================================
+ Coverage     52.3431%   52.4020%   +0.0589%     
- Complexity      18296      18309        +13     
==================================================
  Files            2036       2036                
  Lines           96347      96380        +33     
  Branches        16829      16837         +8     
==================================================
+ Hits            50431      50505        +74     
+ Misses          38492      38445        -47     
- Partials         7424       7430         +6     
Files with missing lines Coverage Δ
...ls/gradle/plugin/views/gsp/GroovyPagePlugin.groovy 56.0606% <100.0000%> (+56.0606%) ⬆️
.../plugin/views/gsp/GroovyPageForkCompileTask.groovy 25.9259% <0.0000%> (+25.9259%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant