diff --git a/src/main/java/org/codehaus/gmavenplus/util/GroovyCompiler.java b/src/main/java/org/codehaus/gmavenplus/util/GroovyCompiler.java index fe6d596e..e2d9e5f4 100644 --- a/src/main/java/org/codehaus/gmavenplus/util/GroovyCompiler.java +++ b/src/main/java/org/codehaus/gmavenplus/util/GroovyCompiler.java @@ -16,6 +16,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.CodeSource; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -250,6 +251,21 @@ public class GroovyCompiler { */ protected static final Version JAVA_12 = new Version(12); + /** + * The mapping of javac target to Groovy target bytecode. + */ + private static final Map JAVAC_TARGET_TO_TARGET_BYTECODE; + + static { + Map javacTargetToTargetBytecode = new HashMap<>(); + javacTargetToTargetBytecode.put("5", "1.5"); + javacTargetToTargetBytecode.put("6", "1.6"); + javacTargetToTargetBytecode.put("7", "1.7"); + javacTargetToTargetBytecode.put("8", "1.8"); + javacTargetToTargetBytecode.put("1.9", "9"); + JAVAC_TARGET_TO_TARGET_BYTECODE = Collections.unmodifiableMap(javacTargetToTargetBytecode); + } + private final ClassWrangler classWrangler; private final Log log; @@ -758,13 +774,7 @@ protected void verifyGroovyVersionSupportsTargetBytecode(String targetBytecode) } public static String translateJavacTargetToTargetBytecode(String targetBytecode) { - Map javacTargetToTargetBytecode = new HashMap<>(); - javacTargetToTargetBytecode.put("5", "1.5"); - javacTargetToTargetBytecode.put("6", "1.6"); - javacTargetToTargetBytecode.put("7", "1.7"); - javacTargetToTargetBytecode.put("8", "1.8"); - javacTargetToTargetBytecode.put("1.9", "9"); - return javacTargetToTargetBytecode.getOrDefault(targetBytecode, targetBytecode); + return JAVAC_TARGET_TO_TARGET_BYTECODE.getOrDefault(targetBytecode, targetBytecode); } protected boolean isJavaSupportIndy() {