Document, how to set Java language version
Discussed in https://github.com/com-lihaoyi/mill/discussions/4925
Originally posted by asarkar April 12, 2025 Nowhere in the Building Java with Mill, was I able to find a way to set the language/target version. Gradle does it as follows:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
Surely there's a way to specify this in the build file regardless of the compiler version used for the build, right?
Isn't this https://mill-build.org/mill/fundamentals/configuring-jvm-versions.html?
No, this selects the JVM/JDK to use. This also means, without further configuration, compiled class files target this JVM version or newer. But you typically want to explicitly set your supported baseline to not accidentally exclude your target platform by using a newer compiler, e.g. in Mill we set it to -source 1.8 -target 1.8. On newer JVMs there is a --release option.
Maybe we should add an explicit jvmTarget task to JavaModule. It's something almost any library author needs to configure at some point. Since this is something coherent for all derived modules too, an explicit jvmTarget task could significantly reduce misconfiguration before a bad release happens.
From what I can tell, the gradle code in the original ticket does exactly the same as the Configuring JVM Versions doc linked, so the original request is already satisfied
@lihaoyi, you're right. The OP snippet does select the toolchain, not the --release flag I was referring to.