Skip to content

Commit bae00b7

Browse files
committed
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.
1 parent ef20c37 commit bae00b7

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ To build `freemarker.jar`, just issue `./gradlew jar` (`gradlew.bat jar` on Wind
125125
project root directory, and it should download all dependencies automatically, and build
126126
`freemarker.jar`.
127127

128+
**Note if you have trouble building on MacOS / Apple Silicon / aarch64**
129+
130+
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:
131+
132+
`./gradlew -Pfreemarker.skipJavaMRJSourceSets=true jar`
133+
134+
This is helpful if you have trouble finding a JDK9 / JDK16 for MacOS.
135+
136+
128137
To run all JUnit tests and some other checks, issue `./gradlew check`. (Avoid the
129138
`test` task, as that will only run the tests of the `core` source set.)
130139

build.gradle.kts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ group = "org.freemarker"
3535

3636
val fmExt = freemarkerRoot
3737

38+
// HACK: disable MR-JAR source sets locally on Apple Silicon without JDK 9 / 16
39+
val skipJavaMRJSourceSets = providers
40+
.gradleProperty("freemarker.skipJavaMRJSourceSets")
41+
.map(String::toBoolean)
42+
.getOrElse(false)
43+
3844
tasks.withType<JavaCompile>().configureEach {
3945
options.encoding = "UTF-8"
4046
}
@@ -61,10 +67,14 @@ freemarkerRoot {
6167
configureSourceSet("jython20")
6268
configureSourceSet("jython22")
6369
configureSourceSet("jython25") { enableTests() }
64-
configureSourceSet("core9", "9") { enableTests() }
65-
configureSourceSet("core16", "16") {
70+
71+
72+
if (!skipJavaMRJSourceSets) {
73+
configureSourceSet("core9", "9") { enableTests() }
74+
configureSourceSet("core16", "16") {
6675
enableTests();
67-
addDependencySourceSet("core9");
76+
addDependencySourceSet("core9");
77+
}
6878
}
6979

7080
configureGeneratedSourceSet("jakartaServlet") {
@@ -592,15 +602,15 @@ registerDistRatTask("ratDistSrc", file("rat-excludes"), distSrc)
592602

593603
eclipse {
594604
classpath {
595-
// Eclipse sees only a single classpath,
596-
// so make a best effort for a combined classpath.
597-
plusConfigurations = listOf(
598-
configurations["combinedClasspath"],
599-
configurations["core9CompileClasspath"],
600-
configurations["core16CompileClasspath"],
601-
configurations["testUtilsCompileClasspath"],
602-
configurations["javaxServletTestCompileClasspath"]
603-
)
605+
plusConfigurations = buildList {
606+
add(configurations["combinedClasspath"])
607+
if (!skipJavaMRJSourceSets) {
608+
add(configurations["core9CompileClasspath"])
609+
add(configurations["core16CompileClasspath"])
610+
}
611+
add(configurations["testUtilsCompileClasspath"])
612+
add(configurations["javaxServletTestCompileClasspath"])
613+
}
604614
}
605615
}
606616

0 commit comments

Comments
 (0)