https://kotlinlang.org logo
#ksp
Title
# ksp
j

jean

11/15/2023, 8:02 PM
After modularizing a project using a ksp processor I get the following error
Copy code
A problem occurred configuring project ':logic'.
> Could not create task ':logic:compileKotlinIosArm64'.
   > Task with name 'kspCommonMainKotlinMetadata' not found in project ':logic'.
logic
is the name of my module. I did work all good when I had a single module structure. I did add the plugins the same way it’s done hete https://github.com/google/ksp/blob/main/examples/multiplatform/workload/build.gradle.kts Any idea how I can fix this?
t

Ting-Yuan Huang

11/15/2023, 8:54 PM
Is there any explicit use of task names, such as the
TaskCollection.getByName
? https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskCollection.html
Gradle stack trace might also give some insights
j

jean

11/15/2023, 8:57 PM
I think it comes from this
Copy code
dependencies {
    add("kspCommonMainMetadata", "com.jeantuffier.statemachine:processor:$stateMachineVersion")
}
t

Ting-Yuan Huang

11/15/2023, 9:16 PM
Looking at line 402 of the stack trace, may I know what your build.gradle.kts looks like at line 170 - 171?
j

jean

11/16/2023, 7:31 AM
Copy code
tasks.withType<KotlinNativeCompile>().configureEach {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}
I did add a bunch of similar tasks because the compiler was asking for it a while ago
I had to add this in order to build/compile
Copy code
dependencies {
    add("kspCommonMainMetadata", "com.jeantuffier.statemachine:processor:$stateMachineVersion")
}

tasks.named("build") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}

tasks.withType<KotlinCompile>().configureEach {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}

tasks.withType<KotlinNativeCompile>().configureEach {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}

tasks.named("compileKotlinJvm") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}

tasks.named("jvmSourcesJar") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}

tasks.named("sourcesJar") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}
t

Ting-Yuan Huang

11/16/2023, 4:40 PM
The KSP task isn't created because there isn't corresponding compilation task. This is possible when, for example, the common source is only used by one target, or only jvm targets, where a klib / metadata compilation isn't needed. On the other hand, KSP should wire up the necessary dependencies. If not, it is a bug in KSP. Could you remove those explicit dependencies and show me the error messages?
j

jean

11/16/2023, 7:31 PM
Copy code
* What went wrong:
A problem was found with the configuration of task ':logic:compileDebugKotlinAndroid' (type 'KotlinCompile').
  - Gradle detected a problem with the following location: '.../logic/build/generated/ksp/metadata/commonMain/kotlin'.
    
    Reason: Task ':logic:compileDebugKotlinAndroid' uses this output of task ':logic:kspCommonMainKotlinMetadata' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':logic:kspCommonMainKotlinMetadata' as an input of ':logic:compileDebugKotlinAndroid'.
      2. Declare an explicit dependency on ':logic:kspCommonMainKotlinMetadata' from ':logic:compileDebugKotlinAndroid' using Task#dependsOn.
      3. Declare an explicit dependency on ':logic:kspCommonMainKotlinMetadata' from ':logic:compileDebugKotlinAndroid' using Task#mustRunAfter.
    
    For more information, please refer to <https://docs.gradle.org/8.2/userguide/validation_problems.html#implicit_dependency> in the Gradle documentation.
I’ll add
logic:
to all the tasks and see if it fixes the issue
Nop, if I add
Copy code
tasks.named(":logic:compileDebugKotlinAndroid") {
    dependsOn(tasks.named(":logic:kspCommonMainKotlinMetadata"))
}
as suggested in
Declare an explicit dependency on ':logic:kspCommonMainKotlinMetadata' from ':logic:compileDebugKotlinAndroid' using Task#dependsOn
I get the following error
I found a solution but it seems like it’s not fixing the original issue, more like a consequences of it https://kotlinlang.slack.com/archives/C19FD9681/p1700168419892299
3 Views