Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gradle's JavaToolchain support for new Kotlin projects #2532

Open
2 of 4 tasks
itsandreramon opened this issue Jul 11, 2024 · 1 comment
Open
2 of 4 tasks

Use Gradle's JavaToolchain support for new Kotlin projects #2532

itsandreramon opened this issue Jul 11, 2024 · 1 comment

Comments

@itsandreramon
Copy link

itsandreramon commented Jul 11, 2024

Description

Generating a new JDK 21 Kotlin Gradle project when using JDK 22 locally results in Kotlin target JDK mismatch causing the sync to fail. For example, new Spring Boot projects automatically set the Java language version using Gradle's JavaToolchain support.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a starter using Java 21 w/o any plugins using Kotlin & Kotlin Gradle
  2. Have JDK 22 as Java Home
  3. Sync project, notice the warning that Kotlin is incompatible with 22 JDK target, it downgrades to 21 automatically
    Kotlin does not yet support 22 JDK target, falling back to Kotlin JVM_21 JVM target
  4. Change Java sourceCompatability to 17
  5. Try to resync & run the app and notice error:
    > Inconsistent JVM-target compatibility detected for tasks 'compileJava' (17) and 'kspKotlin' (21).

Expected Behaviour

kspKotlin and compileJava should use the same language version automatically.

Actual Behaviour

kspKotlin and compileJava use different JVM target versions.

Environment Information

  • Operating System: Mac OS X 14.5 aarch64
  • Micronaut Version: 4.5.0
  • JDK Version: JDK22
@itsandreramon
Copy link
Author

itsandreramon commented Jul 11, 2024

This issue is resolved automatically using

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant