From 83bf98e5e62ed5c2b3b9ded6b550f5365e1ec7b3 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Fri, 29 May 2026 21:54:57 +0200 Subject: [PATCH 1/3] 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. --- README.md | 9 +++++++++ build.gradle.kts | 32 ++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 74bd324fb..8b1461db0 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,15 @@ To build `freemarker.jar`, just issue `./gradlew jar` (`gradlew.bat jar` on Wind project root directory, and it should download all dependencies automatically, and build `freemarker.jar`. +**Note if you have trouble 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.`) try this as a local-only-developer-hack: + +`./gradlew -Pfreemarker.skipJavaMRJSourceSets=true jar` + +This is helpful if you have trouble finding a JDK9 / JDK16 for MacOS. + + To run all JUnit tests and some other checks, issue `./gradlew check`. (Avoid the `test` task, as that will only run the tests of the `core` source set.) diff --git a/build.gradle.kts b/build.gradle.kts index 3f514ac91..858215a85 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,12 @@ group = "org.freemarker" val fmExt = freemarkerRoot +// HACK: disable MR-JAR source sets locally on Apple Silicon without JDK 9 / 16 +val skipJavaMRJSourceSets = providers + .gradleProperty("freemarker.skipJavaMRJSourceSets") + .map(String::toBoolean) + .getOrElse(false) + tasks.withType().configureEach { options.encoding = "UTF-8" } @@ -61,10 +67,14 @@ freemarkerRoot { configureSourceSet("jython20") configureSourceSet("jython22") configureSourceSet("jython25") { enableTests() } - configureSourceSet("core9", "9") { enableTests() } - configureSourceSet("core16", "16") { + + + if (!skipJavaMRJSourceSets) { + configureSourceSet("core9", "9") { enableTests() } + configureSourceSet("core16", "16") { enableTests(); - addDependencySourceSet("core9"); + addDependencySourceSet("core9"); + } } configureGeneratedSourceSet("jakartaServlet") { @@ -594,13 +604,15 @@ eclipse { classpath { // Eclipse sees only a single classpath, // so make a best effort for a combined classpath. - plusConfigurations = listOf( - configurations["combinedClasspath"], - configurations["core9CompileClasspath"], - configurations["core16CompileClasspath"], - configurations["testUtilsCompileClasspath"], - configurations["javaxServletTestCompileClasspath"] - ) + plusConfigurations = buildList { + add(configurations["combinedClasspath"]) + if (!skipJavaMRJSourceSets) { + add(configurations["core9CompileClasspath"]) + add(configurations["core16CompileClasspath"]) + } + add(configurations["testUtilsCompileClasspath"]) + add(configurations["javaxServletTestCompileClasspath"]) + } } } From 135e32f2792f99e713a0b94b7bca1b1fee90c202 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Mon, 1 Jun 2026 19:43:45 +0200 Subject: [PATCH 2/3] Revert "Add Apple Silicon build workaround" This reverts commit 83bf98e5e62ed5c2b3b9ded6b550f5365e1ec7b3. --- README.md | 9 --------- build.gradle.kts | 32 ++++++++++---------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8b1461db0..74bd324fb 100644 --- a/README.md +++ b/README.md @@ -125,15 +125,6 @@ To build `freemarker.jar`, just issue `./gradlew jar` (`gradlew.bat jar` on Wind project root directory, and it should download all dependencies automatically, and build `freemarker.jar`. -**Note if you have trouble 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.`) try this as a local-only-developer-hack: - -`./gradlew -Pfreemarker.skipJavaMRJSourceSets=true jar` - -This is helpful if you have trouble finding a JDK9 / JDK16 for MacOS. - - To run all JUnit tests and some other checks, issue `./gradlew check`. (Avoid the `test` task, as that will only run the tests of the `core` source set.) diff --git a/build.gradle.kts b/build.gradle.kts index 858215a85..3f514ac91 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,12 +35,6 @@ group = "org.freemarker" val fmExt = freemarkerRoot -// HACK: disable MR-JAR source sets locally on Apple Silicon without JDK 9 / 16 -val skipJavaMRJSourceSets = providers - .gradleProperty("freemarker.skipJavaMRJSourceSets") - .map(String::toBoolean) - .getOrElse(false) - tasks.withType().configureEach { options.encoding = "UTF-8" } @@ -67,14 +61,10 @@ freemarkerRoot { configureSourceSet("jython20") configureSourceSet("jython22") configureSourceSet("jython25") { enableTests() } - - - if (!skipJavaMRJSourceSets) { - configureSourceSet("core9", "9") { enableTests() } - configureSourceSet("core16", "16") { + configureSourceSet("core9", "9") { enableTests() } + configureSourceSet("core16", "16") { enableTests(); - addDependencySourceSet("core9"); - } + addDependencySourceSet("core9"); } configureGeneratedSourceSet("jakartaServlet") { @@ -604,15 +594,13 @@ eclipse { classpath { // Eclipse sees only a single classpath, // so make a best effort for a combined classpath. - plusConfigurations = buildList { - add(configurations["combinedClasspath"]) - if (!skipJavaMRJSourceSets) { - add(configurations["core9CompileClasspath"]) - add(configurations["core16CompileClasspath"]) - } - add(configurations["testUtilsCompileClasspath"]) - add(configurations["javaxServletTestCompileClasspath"]) - } + plusConfigurations = listOf( + configurations["combinedClasspath"], + configurations["core9CompileClasspath"], + configurations["core16CompileClasspath"], + configurations["testUtilsCompileClasspath"], + configurations["javaxServletTestCompileClasspath"] + ) } } From 12418b572f000dd41bbf25ec662f446252eb8259 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Mon, 1 Jun 2026 19:55:07 +0200 Subject: [PATCH 3/3] 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. --- build.gradle.kts | 13 +++++++++++-- gradle.properties | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3f514ac91..c7995514a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,15 @@ group = "org.freemarker" val fmExt = freemarkerRoot + +val core9JavaVersion = providers + .gradleProperty("freemarker.core9.javaVersion") + .get() + +val core16JavaVersion = providers + .gradleProperty("freemarker.core16.javaVersion") + .get() + tasks.withType().configureEach { options.encoding = "UTF-8" } @@ -61,8 +70,8 @@ freemarkerRoot { configureSourceSet("jython20") configureSourceSet("jython22") configureSourceSet("jython25") { enableTests() } - configureSourceSet("core9", "9") { enableTests() } - configureSourceSet("core16", "16") { + configureSourceSet("core9", core9JavaVersion) { enableTests() } + configureSourceSet("core16", core16JavaVersion) { enableTests(); addDependencySourceSet("core9"); } diff --git a/gradle.properties b/gradle.properties index 46ce0468c..1a4847465 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,10 +21,14 @@ # 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.core9.javaVersion=11 +# JDK version used for compiling the Java 16 MR-JAR source set +freemarker.core16.javaVersion=17 # JDK version for running javadoc -freemarker.javadoc.javaVersion=16 +freemarker.javadoc.javaVersion=17 # JDK version for running JUnit tests -freemarker.test.javaVersion=16 +freemarker.test.javaVersion=17 # Method used when generating the *.asc file, one of: none, gradle_properties, gpg_command freemarker.signMethod=none