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

Support K2 #545

Open
Nek-12 opened this issue Dec 13, 2023 · 7 comments · May be fixed by #643
Open

Support K2 #545

Nek-12 opened this issue Dec 13, 2023 · 7 comments · May be fixed by #643
Labels
enhancement New feature or request

Comments

@Nek-12
Copy link

Nek-12 commented Dec 13, 2023

Currently, trying to build with KSP2 / K2 fails with:

Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction
	<junk>
Caused by: java.lang.NoClassDefFoundError: javaslang/collection/HashMap
	at org.jetbrains.kotlin.load.java.structure.impl.classFiles.ClassifierResolutionContext.<init>(ClassifierResolutionContext.kt:40)
	at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt$getDefaultValue$1$2$visitMethod$1.visitAnnotationDefault(util.kt:435)
	at org.jetbrains.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1364)
	at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:712)
	at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:395)
	at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt.getDefaultValue(util.kt:422)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:77)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:60)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getDefaultArguments(KSAnnotationImpl.kt:60)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:54)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:51)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getArguments(KSAnnotationImpl.kt:51)
	at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenDestinationsMapper.toDestination(KspToCodeGenDestinationsMapper.kt:557)
	at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenDestinationsMapper.access$toDestination(KspToCodeGenDestinationsMapper.kt:67)
	at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenDestinationsMapper$map$1.invoke(KspToCodeGenDestinationsMapper.kt:78)
	at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenDestinationsMapper$map$1.invoke(KspToCodeGenDestinationsMapper.kt:78)
	at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
	at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:811)
	at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenDestinationsMapper.map(KspToCodeGenDestinationsMapper.kt:78)
	at com.ramcosta.composedestinations.ksp.processors.Processor.process(Processor.kt:55)
	at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:464)
	<junk>
	... 2 more
Caused by: java.lang.ClassNotFoundException: javaslang.collection.HashMap
	... 56 more

gradle.properties:

kotlin.experimental.tryK2=true
android.lint.useK2Uast=true
ksp.useKSP2=true
@raamcosta raamcosta added the enhancement New feature or request label Jan 2, 2024
@Nek-12
Copy link
Author

Nek-12 commented May 19, 2024

Looks like K2 is enabled by default in Kotlin 2.0. Did anyone get the library working with k2 enabled?

@FooIbar
Copy link

FooIbar commented May 19, 2024

You can use it with K2, we've been doing that for a while, just don't use KSP2.

@FooIbar
Copy link

FooIbar commented May 21, 2024

Looks like FooIbar@7875839 is the only change needed to support KSP2.
Note KSP 1.0.20 does not have google/ksp#1871, so those arguments that have class literals as default values need to be explicitly specified, e.g.

@Destination<RootGraph>(navArgs = Nothing::class, style = DestinationStyle.Default::class)

@raamcosta
Copy link
Owner

Ok thank you @FooIbar

But just so we're clear. Using 1.0.20 KSP means we'd have to specify all field defaults for annotations that have class types, but only if using K2 as well, right?

@FooIbar
Copy link

FooIbar commented May 21, 2024

Ok thank you @FooIbar

But just so we're clear. Using 1.0.20 KSP means we'd have to specify all field defaults for annotations that have class types, but only if using K2 as well, right?

Yes, only if using KSP2.
That fix has been cherry-picked to the 1.0.21 branch google/ksp@fc0cdbf, which should be released soon?

@raamcosta
Copy link
Owner

You scared me for a moment.. I thought for a moment that they would be dropping that completely 😅 made no sense but we never know..

@FooIbar
Copy link

FooIbar commented May 21, 2024

You scared me for a moment.. I thought for a moment that they would be dropping that completely 😅 made no sense but we never know..

I should have made it clearer. That is only for testing KSP2 compatibility with 1.0.20 FooIbar@d7e79dd.

Update: Tested with 1.0.21, it's only partially fixed. Filed a bug on KSP google/ksp#1910.

@FooIbar FooIbar linked a pull request May 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants