Allow interpreters to target a specific bytecode version - #201
Open
adityaanikam wants to merge 1 commit into
Open
Allow interpreters to target a specific bytecode version#201adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
See apache/maven-invoker-plugin#742 Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
adityaanikam
force-pushed
the
groovy-target-bytecode-742
branch
from
August 5, 2026 21:46
75d12ff to
877261a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
Groovy's
CompilerConfigurationdefaults its target bytecode to whatever JDK is currentlyrunning it (
defaultTargetBytecode()reads the running JVM's version), with no way to overrideit. This means
verify.groovyhook scripts get compiled to the executing JDK's bytecode levelregardless of the project's own
maven.compiler.release, which breaks old source revisions asthe JDK running the build evolves. See apache/maven-invoker-plugin#742 for the full report.
This PR adds a
setTargetBytecode(String)method through the interpreter stack:ScriptInterpretergets a default no-op method (interpreters like BeanShell that don't compileto a bytecode level can ignore it).
GroovyScriptInterpreterimplements it, storing the value and applying it to theCompilerConfigurationused inevaluateScript(). A smallnormalizeTargetBytecodehelpermaps Maven-style release values (
"8") to the form Groovy'ssetTargetBytecodeexpects(
"1.8"for JDK 4-8, bare numbers from JDK 9 on).ScriptRunnerexposes the same setter, applying it to all registered interpreters.This only adds the capability to
maven-script-interpreter. Wiringmaven-invoker-plugintoread
maven.compiler.releaseand call this new setter is a separate follow-up PR against thatrepo, since it depends on this change being available.
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify).(N/A — this repo has no
run-itsprofile or integration-test suite.)If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.