Is there any chance of support for ".java-version"...
# community-support
e
Is there any chance of support for ".java-version" being added to Gradle, i.e. if there is a
.java-version
file it would be used to set the daemon toolchain?
👀 1
1
til 1
m
+1, that'd be handy. Reference for those like me who didn't knwo about
.java-version
Although I'm slightly annoyed that all these tools set a fixed version. Usually my constraint is more of a minimum version
I don't want to download Java 17 if I have Java 25 installed locally
v
I'd say the chance is 0 when just asking here which is mainly a community place. :-D Open a feature request and you will see what the Gradle folks think about it. I personally think it could maybe be used for something, but whether it will be the daemon toolchain or the project toolchain, or whether it really makes sense, especially as Gradle already has the capability and that is a non-standard file of a non-standard tool that I didn't heard of to date or forgot about. 🤷‍♂️
a
you could probably set it up at the moment, along with Martin's suggestion to use it as a minimum
Copy code
tasks.updateDaemonJvm {
  val requestedJavaVersion =
    layout.projectDirectory.file(".java-version")
      .asFile
      .takeIf { it.exists() }
      ?.readText()
      ?.let { JavaLanguageVersion.of(it) }
      ?.takeIf { it > JavaLanguageVersion.current() }

  if (requestedJavaVersion != null) {
    languageVersion = requestedJavaVersion
  }
}
(I haven't tested this)
v
The check against current is probably not a good idea, because you maybe have 15 in the daemon spec, 16 in the file, but running locally using 17, so the daemon spec would not be updated to 16 and then fail for others that use the daemon spec. And of course, you have to call the update-task to update the daemon spec after you changed the file. But other than that, you should of course be able to get the version to write to the spec from the file, yes. 🙂