You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2025/10/21 15:55:57 UTC

(groovy) branch GROOVY-11790 created (now 78910aac0b)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY-11790
in repository https://gitbox.apache.org/repos/asf/groovy.git


      at 78910aac0b GROOVY-11790: set `--release` option if no source, target, or release

This branch includes the following new commits:

     new 78910aac0b GROOVY-11790: set `--release` option if no source, target, or release

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(groovy) 01/01: GROOVY-11790: set `--release` option if no source, target, or release

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-11790
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 78910aac0b7ad8d3793ee6e3b005d5fb5c9d30ae
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Oct 21 10:55:23 2025 -0500

    GROOVY-11790: set `--release` option if no source, target, or release
---
 .../codehaus/groovy/tools/javac/JavacJavaCompiler.java  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
index b5231552ba..9ff312f7bb 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
@@ -144,10 +144,12 @@ public class JavacJavaCompiler implements JavaCompiler {
 
         Map<String, Object> options = config.getJointCompilationOptions();
         boolean classpath = false;
+        boolean release = false;
 
         if (options.get("flags") instanceof String[] flags) {
             for (String flag : flags) {
                 if (flag == null) continue;
+                if (!release) release = isReleaseParameter(flag.split("=")[0]);
 
                 params.add("-" + flag);
             }
@@ -157,13 +159,20 @@ public class JavacJavaCompiler implements JavaCompiler {
             for (int i = 0, n = namedValues.length; i < n; i += 2) {
                 var name = namedValues[i];
                 if (name == null) continue;
-                if (!classpath) classpath = isClasspathParameter(name);
+                if (!release && isReleaseParameter(name)) release = true;
+                else if (!classpath) classpath = isClasspathParameter(name);
 
                 params.add("-" + name);
                 params.add(namedValues[i + 1]);
             }
         }
 
+        // GROOVY-11790
+        if (!release) {
+            params.add("--release");
+            params.add(config.getTargetBytecode());
+        }
+
         // append classpath if not already defined
         if (!classpath) {
             // add class paths of compilation unit
@@ -198,6 +207,12 @@ public class JavacJavaCompiler implements JavaCompiler {
         return param.equals("cp") || param.equals("classpath") || param.equals("-class-path");
     }
 
+    private static boolean isReleaseParameter(final String param) {
+        return param.equals("source")  || param.equals("-source")
+            || param.equals("target")  || param.equals("-target")
+            || param.equals("release") || param.equals("-release");
+    }
+
     @SuppressWarnings("removal") // TODO a future Groovy version should perform the operation not as a privileged action
     private static java.security.CodeSource getCodeSource() {
         return java.security.AccessController.doPrivileged((java.security.PrivilegedAction<java.security.CodeSource>) () ->