Closed IceBlizz6 closed 6 days ago
Looking at their tests: the issue is that you have done none of the following:
set the language version to <2.0
class Tests {
@Test
@OptIn(ExperimentalCompilerApi::class)
fun isMySymbolProcessorProviderCalled() {
val compilation = KotlinCompilation().apply {
languageVersion = "1.9" // this can really just be anything that is less than 2.0
configureKsp {
symbolProcessorProviders += MySymbolProcessorProvider()
}
}
compilation.compile()
Assert.assertTrue(provider.called)
}
}
enabled ksp2:
class Tests {
@Test
@OptIn(ExperimentalCompilerApi::class)
fun isMySymbolProcessorProviderCalled() {
val compilation = KotlinCompilation().apply {
configureKsp(useKsp2 = true) {
symbolProcessorProviders += MySymbolProcessorProvider()
}
}
compilation.compile()
Assert.assertTrue(provider.called)
}
}
Yeah, second part works with Kotlin 2.0.21 from what i can see, the code passes now.
You forgot to make the provider variable in your sample so i fixed it and here is the new code:
@Test
@OptIn(ExperimentalCompilerApi::class)
fun isMySymbolProcessorProviderCalled() {
val provider = MySymbolProcessorProvider()
val compilation = KotlinCompilation().apply {
configureKsp(useKsp2 = true) {
symbolProcessorProviders += provider
}
}
compilation.compile()
Assert.assertTrue(provider.called)
}
So the important change here is the line symbolProcessorProviders += provider
inside configureKsp(useKsp2 = true) {
because that is different from referencing symbolProcessorProviders
directly inside KotlinCompilation().apply
I will close this as it has been solved, but do consider adding something like this to the readme.
Been spending a lot of time trying to figure out how to make compilation use KSP. Tried adding kspWithCompilation, calling different combinations of useKsp2 and configureKsp. I think i'm just stumbling around in the dark.
A guide would be very helpful.
So this test works as expected with
kotlin-compile-testing-ksp:1.6.0
Changing dependencies to the below and now it seems like no matter what i do the test will never pass.