diff --git a/README.md b/README.md index 0b838e5ff..fae272cc1 100644 --- a/README.md +++ b/README.md @@ -251,3 +251,24 @@ Gradle project. After that, it's recommended to set these preferences (based on - Project -> Properties -> FindBugs -> [x] Run Automatically - There should 0 errors. But sometimes the plugin fails to take the @SuppressFBWarnings annotations into account; then use Project -> Clean. + + +## Troubleshooting + +### Problems building on MacOS / Apple Silicon / aarch64 + +If you run into build problems on MacOS (e.g. `No matching toolchains found for requested specification: {languageVersion=9, vendor=any, implementation=vendor-specific} for MAC_OS on aarch64.`) that means that you don't have JDK9 / JDK16 installed on your system. + +You override the java versions used for JDK9 and JDK16: + +``` +./gradlew -Pfreemarker.javaVersionUsedFor.9=11 -Pfreemarker.javaVersionUsedFor.16=17 jar +``` + +This is helpful if you don't have a JDK9 / JDK16 for MacOS installed on your system and just want to build e.g. with another replacement locally during development. + +You can append `--info` to get diagnostic output like this: + +``` +TOOLCHAIN :compileCore16Java: lang=17 vendor=Eclipse Temurin runtime=17.0.11+9 home=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home +``` diff --git a/build.gradle.kts b/build.gradle.kts index 3f514ac91..fb576ccbd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,23 @@ group = "org.freemarker" val fmExt = freemarkerRoot + +/* +* Additional diagnostic output when you want to find output +* which Java version is used for which part. +* enable with --info +*/ +tasks.withType().configureEach { + doFirst { + val md = javaCompiler.get().metadata + logger.info( + "TOOLCHAIN ${path}: lang=${md.languageVersion.asInt()} " + + "vendor=${md.vendor} runtime=${md.javaRuntimeVersion} " + + "home=${md.installationPath.asFile}" + ) + } +} + tasks.withType().configureEach { options.encoding = "UTF-8" } @@ -61,8 +78,8 @@ freemarkerRoot { configureSourceSet("jython20") configureSourceSet("jython22") configureSourceSet("jython25") { enableTests() } - configureSourceSet("core9", "9") { enableTests() } - configureSourceSet("core16", "16") { + configureSourceSet("core9", javaVersionUsedFor(9).toString()) { enableTests() } + configureSourceSet("core16", javaVersionUsedFor(16).toString()) { enableTests(); addDependencySourceSet("core9"); } @@ -733,3 +750,8 @@ dependencies { "testUtilsImplementation"("commons-collections:commons-collections:3.1") "testUtilsImplementation"("commons-lang:commons-lang:2.6") } + +fun javaVersionUsedFor(requestedVersion: Int): Int { + val overrideVersion = project.findProperty("freemarker.javaVersionUsedFor.$requestedVersion")?.toString()?.toIntOrNull() + return overrideVersion ?: requestedVersion +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 46ce0468c..15a0245b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,6 +21,10 @@ # JDK version used for compiling, except for Source Sets where a specific version is set in build.gradle.kts. freemarker.javaVersion=8 +# JDK version used for compiling the Java 9 MR-JAR source set +freemarker.javaVersionUsedFor.9=9 +# JDK version used for compiling the Java 16 MR-JAR source set +freemarker.javaVersionUsedFor.16=16 # JDK version for running javadoc freemarker.javadoc.javaVersion=16 # JDK version for running JUnit tests