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?David Herman
11/01/2023, 5:52 PMTing-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 PMDavid Herman
11/01/2023, 9:58 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.Ting-Yuan Huang
11/01/2023, 10:08 PMcompileKotlin
directly: https://github.com/google/ksp/blob/main/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt#L539Ting-Yuan Huang
11/01/2023, 10:11 PMsource
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.David Herman
11/01/2023, 10:27 PMTing-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 PMDavid Herman
11/01/2023, 10:29 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 PMDavid Herman
11/01/2023, 10:29 PMDavid Herman
11/01/2023, 10:29 PMDavid Herman
11/01/2023, 10:30 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);
}
David Herman
11/01/2023, 10:35 PM@HasImplicitReceiver
is what results in the value being a "this" and not an "it"David Herman
11/01/2023, 10:36 PMDavid Herman
11/01/2023, 10:38 PMTing-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 PMDavid Herman
11/01/2023, 11:16 PMsource
was the way to go, and a lot easier than what we thought we had to do. Thank you!David Herman
11/29/2023, 5:55 AMsource
)
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 AMDavid Herman
11/30/2023, 12:53 AMsource
apparentlyDavid Herman
11/30/2023, 1:07 AMDavid Herman
02/20/2024, 12:45 AMDavid Herman
02/20/2024, 12:57 AMTing-Yuan Huang
02/27/2024, 10:45 PMTing-Yuan Huang
02/27/2024, 10:48 PMTing-Yuan Huang
02/27/2024, 10:50 PMDavid Herman
02/28/2024, 1:51 AM@Page
annotation. We do not actually generate source in our KSP processor, but we generate resources (json files describing important entries in the code). I'll attach an example json file to this comment.
Next, our Gradle plugin discovers these json files in the project, using them to generate code. Let's call this task "generateSite"
In our mind, this would be ideal:
• Run KSP processor, generate resources
• Run "generateSite", which processes the resources and generates code
However, KSP's current design (as far as I can tell) wants all source to be ready before it runs. It either wants the source to be there or, if generated, is generated by it itself.
We get an error when we try to add the output of the "generateSite" task to the Kotlin sourceset:
kotlin.srcDir(generateSite)
Specifically, Gradle reports a circular dependency between kspKotlinJs and generateSite.
For now, based on our discussion from a few months ago, we are doing this as a workaround:
kotlinCompileTask.configure { source(generateSite) }
But that option will no longer be available to use in K2.Ting-Yuan Huang
02/28/2024, 5:07 PMKspExtension.excludeSrcDirs
.
Another approach is to call KSP2 programmatically and skip KSP's gradle plugin completely, now that you're manipulating sources directly.David Herman
02/28/2024, 5:50 PMDavid Herman
02/28/2024, 5:51 PMgeneratedByKsp
sourceset (which I assume was removed for some technical reason?)Ting-Yuan Huang
02/28/2024, 6:59 PMgeneratedByKsp
to avoid the circular dependency? If so, would doing the same by generating into $buildDir/generated/ksp/$target/$sourceSetName
work for you?
We moved away from generatedByKsp
because Kotlin Gradle Plugin is deprecating the API that registers new source sets to KotlinCompilation
. After discussing with them, their recommendation is adding generated sources directly to the default source set, hence the current KSP implementation.David Herman
02/28/2024, 7:07 PMDavid Herman
02/28/2024, 7:14 PMDavid Herman
02/29/2024, 11:22 PM