libgdx/gdx-liftoff

Created Project with Language Kotlin does not work

vabean opened this issue · 1 comments

When creating a project with gdx-liftoff-1.12.1.4 and selecting Kotlin under Languages, I get this error when trying to open/build the project

> No matching toolchains found for requested specification: {languageVersion=11, vendor=any, implementation=vendor-specific} for LINUX on x86_64.
   > No locally installed toolchains match and toolchain download repositories have not been configured.

* Try:
> Learn more about toolchain auto-detection at https://docs.gradle.org/8.5/userguide/toolchains.html#sec:auto_detection.
> Learn more about toolchain repositories at https://docs.gradle.org/8.5/userguide/toolchains.html#sub:download_repositories.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 459ms

Creating a project without selecting Kotlin does not produce this error.

Ah, it turns out this is something that near-silently was changed in Gradle 8.x; it worked earlier this year on Gradle 7.x. The only thing needed to fix this is to insert some extra configuration into the start of your settings.gradle file (not any of the build.gradle files!):

plugins {
    id('org.gradle.toolchains.foojay-resolver-convention') version '0.7.0'
}
// Below this you should have the previous contents of settings.gradle, with the list of subprojects.

While it's reasonable to be cautious with any downloading plugin, this specific third-party plugin is actually recommended in the Gradle docs: https://docs.gradle.org/current/userguide/toolchains.html#sub:download_repositories It handles downloading a toolchain, which usually means Java 11 for us, and using it throughout the build. Kotlin and Java need to be configured to use identical versions for Kotlin to work, and this was the most sane way I found to do that. The toolchain for, let's say, 11, gets downloaded once into ~/.gradle/ (that is, in the .gradle in your user home folder), and will be reused by any other Gradle projects that use toolchains. JDKs from toolchains can also be treated as normal Java installations; you could set one as your JAVA_HOME for instance.

I've already added the code for settings.gradle in new projects, but there isn't a release yet with it. Should be soon, probably.
Thanks for finding this; I'll close the issue since the code is already present and is just waiting for a release.