David Herman
11/01/2023, 5:50 PMgeneratedByKsp
sourcesets in my project for code that I generate externally that should not get processed by ksp. That just went away in 1.9.20-RC2. Any advice for migration steps?Ting-Yuan Huang
11/01/2023, 8:56 PMcompileKotlin
tasks? KSP takes source set from KGP, not compileKotlin
, so sources direclty added to compileKotlin
won't get processed by default.David Herman
11/01/2023, 8:59 PMcompileKotlin
tasks?
We tried a few options but are still not sure how we're supposed to add them. For example, there is a "source" function but when we try to use it we get "The value for this file collection cannot be changed". Any example code you can link to by any chance?Ting-Yuan Huang
11/01/2023, 10:06 PMsource
? IIUC it should be fine in the configuration phase of Gradle.compileKotlin
directly: https://github.com/google/ksp/blob/main/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt#L539source
cannot be changed is that it is already resolved accidentally at configuration time.David Herman
11/01/2023, 10:18 PMsource
at configuration time. Here's the rough code (a bunch of noise ellided):
Plugin<Project> {
override fun apply(project: Project) {
project.extensions.getByType<KotlinMultiplatformExtension>().targets.withType<KotlinJsIrTarget>().configureEach {
project.tasks.withType(Kotlin2JsCompile::class.java).configureEach {
this.source(genTask)
}
}
}
where genTask
is a Gradle task that is associated with an output source dir.Ting-Yuan Huang
11/01/2023, 10:28 PMthis.source(genTask)
looks fishy to me. Should it be it
?David Herman
11/01/2023, 10:28 PMgenTask
is a task we registered ourselves elsewhere, but we didn't include it in the example aboveTing-Yuan Huang
11/01/2023, 10:29 PMit.source(genTask)
David Herman
11/01/2023, 10:29 PMthis
and not it
because we're using the kotlin-dsl
plugin. this
is Kotlin2JsCompile
Ting-Yuan Huang
11/01/2023, 10:30 PMconfigureEach
it
?David Herman
11/01/2023, 10:35 PMvoid configureEach(Action<? super T> action);
// where...
@HasImplicitReceiver
public interface Action<T> {
void execute(T t);
}
@HasImplicitReceiver
is what results in the value being a "this" and not an "it"Ting-Yuan Huang
11/01/2023, 10:38 PMDavid Herman
11/01/2023, 10:39 PMTing-Yuan Huang
11/01/2023, 10:45 PMproject.tasks.withType(Kotlin2JsCompile::class.java)
also returns ksp tasks. You may need to filter them out: https://github.com/google/ksp/blob/main/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt#L242David Herman
11/01/2023, 11:04 PMsource
was the way to go, and a lot easier than what we thought we had to do. Thank you!source
)
In Kotlin 2.0.0, it looks like this approach is going to stop working. I'm seeing the error Source '...\kobweb\playground\site\build\generated\kobweb\app\src\jvmMain\kotlin\ApisFactoryImpl.kt' does not belong to any module
Have you dealt with this by any chance and already figured out how to resolve it? Does it make sense for KSP to expose an API where we can tell it to exclude processing some code?Ting-Yuan Huang
11/29/2023, 9:06 AMDavid Herman
11/30/2023, 12:53 AMsource
apparently