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

Update to K2 #196

Merged
merged 65 commits into from
Jun 6, 2024
Merged

Update to K2 #196

merged 65 commits into from
Jun 6, 2024

Conversation

ZacSweers
Copy link
Owner

@ZacSweers ZacSweers commented Nov 20, 2023

  • Change supportsK2 to true by default
  • Change disableStandardScript to true by default. This doesn't seem to work yet
  • Update kapt class location refs
  • Support Kapt4
  • Support KSP2

Notes

  • KSP1 and Kapt 3 support require setting languageVersion to 1.9

TODO

  • Support Kapt4, which runs in FIR
  • Support KSP2

@ZacSweers
Copy link
Owner Author

I've published 0.5.0-alpha01 with the changes up to this point in the PR

Some notes

  • Build against Kotlin 2.0.0-Beta1 and KSP 2.0.0-Beta1-1.0.14.
  • To use KSP, you must set KotlinCompilation.languageVersion to 1.9.
  • To use Kapt, you must set the languageVersion to 1.9 or set it to 2.0 and set KotlinCompilation.useKapt4 to true. Kapt 4 is still experimental.
  • KotlinCompilation.supportsK2 is now true by default
  • KotlinCompilation.disableStandardScript is currently now true by default as script support doesn't appear to be supported yet.

@jisungbin
Copy link

Thank you for your quick support of the new Kotlin version!

@ZacSweers
Copy link
Owner Author

ZacSweers commented Feb 3, 2024

I've published 0.5.0-alpha02 with the changes up to this point in the PR.

  • Kotlin 2.0.0-Beta3
  • KSP 2.0.0-Beta3-1.0.17
  • Merged latest main branch changes
  • Implemented initial KSP2 support

Note that KSP 2 and KSP 1 cannot be tested in the same compilation. You would need to do something like I've set up at the build level in this PR to conditionally choose dependencies. There also appears to be a broken dependency in their new Analysis API artifacts (google/ksp#1712), so you'd need to use an exclusion like I've done in this PR. I can publish a new alpha when this is fixed.

In dependencies

ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
ksp-cli = { module = "com.google.devtools.ksp:symbol-processing-cmdline", version.ref = "ksp" }
ksp-aa-embeddable = { module = "com.google.devtools.ksp:symbol-processing-aa-embeddable", version.ref = "ksp" }
ksp-commonDeps = { module = "com.google.devtools.ksp:symbol-processing-common-deps", version.ref = "ksp" }

In the build

// It's not possible to test both KSP 1 and KSP 2 in the same compilation unit
val testKsp2 = providers.systemProperty("kct.test.useKsp2").getOrElse("false").toBoolean()

tasks.test {
  if (testKsp2) {
    systemProperty("kct.test.useKsp2", testKsp2)
  }
}

dependencies {
  if (testKsp2) {
    testImplementation(libs.ksp.aa.embeddable) {
      exclude(group = "com.google.devtools.ksp", module = "common-deps")
    }
    testImplementation(libs.ksp.commonDeps)
    testImplementation(libs.ksp.cli)
  } else {
    testImplementation(libs.ksp)
  }
}

In tests

val useKSP2 = System.getProperty("kct.test.useKsp2", "false").toBoolean()

KotlinCompilation().apply {
  if (useKSP2) {
    useKsp2()
  } else {
    // Fall back to K1
    languageVersion = "1.9"
  }
}

@ZacSweers
Copy link
Owner Author

bug I found: inheritClasspath no longer works for KSP2. Will probably need to do it manually

@ZacSweers
Copy link
Owner Author

I'm unable to repro the inheritClasspath issue I'm seeing in another repo, going to dig into the debugger there

@3flex
Copy link

3flex commented May 18, 2024

Worth an alpha08? It looks like Kotlin 2.0.0 will be based on the same commit as Kotlin 2.0.0-RC3: https://github.com/JetBrains/kotlin/commits/e84e83568cde569ee54980542e37c87507e914bc/

@ZacSweers
Copy link
Owner Author

Only if we need one, otherwise will just wait for 2.0.0 to release

@ZacSweers
Copy link
Owner Author

KSP broke something in the 1.0.21 release google/ksp#1908

@ZacSweers
Copy link
Owner Author

I'm going to publish an alpha08 against the 2.0 finals, but reluctant to publish a non-alpha until there's resolution on the above-linked KSP2 regression. It appears that it only works on linux in 1.0.21. I can't publish yet though because sonatype appears to be down

@ZacSweers
Copy link
Owner Author

ZacSweers commented May 22, 2024

Published 0.5.0-alpha08 see below

@ZacSweers
Copy link
Owner Author

I would actually advise against using 0.5.0-alpha08 due to google/ksp#1917, which I didn't notice before releasing due to inherited extra maven repositories set up on this project that I'll remove.

@3flex
Copy link

3flex commented May 23, 2024

FWIW detekt updated to alpha07 and now alpha08 with Kotlin 2.0.0 and it seems to be working well with cross platform tests all green, though we don't use KSP at all.

Just mentioning as other non-KSP users may be safe to update.

@ZacSweers ZacSweers changed the title Prepare for K2 Update to K2 Jun 6, 2024
@ZacSweers ZacSweers marked this pull request as ready for review June 6, 2024 01:47
@ZacSweers ZacSweers merged commit eb1f3e9 into main Jun 6, 2024
3 checks passed
@ZacSweers ZacSweers deleted the z/k2 branch June 6, 2024 01:52
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

Successfully merging this pull request may close these issues.

None yet

4 participants