Open umpteenthdev opened 1 year ago
This affects more than just builds that use KSP. I have a simple task which produces generated source code that JavaCompile
steps depend on, and see the same failure.
Thanks for the report.
I think this is a bug in Gradle. See https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/685#issuecomment-1650309499. tl;dr you can manually wire the tasks together.
I tried to link tasks before publishing the issue but it didn't work. I have just checked the same implementation you provided in the mentioned issue. It does not work too. You can check it in the sample project. Even after adding the code below
tasks.withType(com.autonomousapps.tasks.CodeSourceExploderTask) {
dependsOn('kspKotlin', "kspDebugKotlin")
}
running ./gradlew buildHealth
twice guarantees the failure.
Here is a more fine-grained workaround for android projects. At least this works for us. It doesn't seem to affect JVM modules in our case.
allprojects {
pluginManager.withPlugin('com.google.devtools.ksp') {
pluginManager.withPlugin('com.android.library') {
androidComponents {
beforeVariants(selector().all()) { variant ->
String variantName = variant.name.capitalize()
tasks.configureEach { task ->
if (task.name == "explodeCodeSource$variantName") {
task.dependsOn("ksp${variantName}Kotlin")
}
}
}
}
}
pluginManager.withPlugin('com.android.application') {
androidComponents {
beforeVariants(selector().all()) { variant ->
String variantName = variant.name.capitalize()
tasks.configureEach { task ->
if (task.name == "explodeCodeSource$variantName") {
task.dependsOn("ksp${variantName}Kotlin")
}
}
}
}
}
}
}
I've explored this a bit more recently, and while the linked antlr plugin issue is a gradle bug (because antlr is a core gradle plugin), this is, more generally, a bug in plugin implementation. For plugins to correctly contribute generated source, such that task dependency information is carried and end users don't need to think about these workarounds, they should do this:
Correct
// pseudocode
sourceSets.main.<java|kotlin|etc>.srcDir(myGeneratingTask.map { it.outputDirectory })
I haven't explored the ksp code, but I assume it's not doing this, and is instead doing something like
Incorrect
// pseudocode
val outputDirectory = project.layout.buildDirectory.dir("my-dir")
myGeneratingTask.configure { t ->
t.outputDirectory.set(outputDirectory)
}
sourceSets.main.<java|kotlin|etc>.srcDir(outputDirectory)
That isn't enough information for Gradle to know which task generates code into that directory, unfortunately.
I started seeing this after adding Compose Multiplatform Resources. Should I be filing something with Jetbrains and pointing them here?
Build scan link https://scans.gradle.com/s/5q4mdauav5xri
Plugin version 1.20.0
Gradle version 8.1.1
(Optional) Android Gradle Plugin (AGP) version 8.0.2
reason
output for bugs relating to incorrect advice N/ADescribe the bug We use KSP in our Android project. During migration to Gradle 8+ we faced failures caused by
buildHealth
task. The issue is that Gradle8 requires dependencies between tasks to be defined explicitly. It seems that dependency analysis plugin uses KSP output directories but does not define any relation to KSP tasks.To Reproduce
./gradlew buildHealth
from the root of the projectExpected behavior
buildHealth
task finished successfully (with or without advice)Additional context