From 5c36655f68a2f0b052f4711eabce7cb1ed636b3f Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Fri, 29 May 2026 21:54:57 +0200 Subject: [PATCH] Add Apple Silicon build workaround Document a local workaround for building on MacOS Apple Silicon and add a Gradle flag to enable it. README.md shows running ./gradlew -Pfreemarker.skipJavaMRJSourceSets=true jar to avoid MR-JAR toolchain errors when JDK9/16 are unavailable. build.gradle.kts adds the skipJavaMRJSourceSets property, conditionally omits configuring the core9/core16 MR-JAR source sets, and updates the Eclipse classpath assembly to avoid referencing those configurations when skipped. Revert "Add Apple Silicon build workaround" This reverts commit 83bf98e5e62ed5c2b3b9ded6b550f5365e1ec7b3. Make core9/core16 Java versions configurable Introduce freemarker.core9.javaVersion and freemarker.core16.javaVersion properties and read them in build.gradle.kts via providers.gradleProperty(); pass those values to configureSourceSet for core9 and core16. Also bump freemarker.javadoc.javaVersion and freemarker.test.javaVersion to 17. This allows compiling the MR-JAR source sets with independent JDK versions (e.g. Java 11 for core9 and Java 17 for core16) configurable from gradle.properties. add javaVersionUsedFor(ver) helper --- README.md | 21 +++++++++++++++++++++ build.gradle.kts | 26 ++++++++++++++++++++++++-- gradle.properties | 4 ++++ 3 files changed, 49 insertions(+), 2 deletions(-) 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