autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.66k stars 116 forks source link

Task ':explodeCodeSource' uses this output of task ':kspKotlin' without declaring an explicit or implicit dependency #1185

Open Mrkchv opened 1 month ago

Mrkchv commented 1 month ago

Plugin version 1.31.0

Gradle version 8.4

JDK version 17

Kotlin and Kotlin Gradle Plugin (KGP) version 1.9.20

Android Gradle Plugin (AGP) version 8.3.2

Describe the bug After bumping to 1.31.0 we get this error:

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':app:kspGoogleDebugKotlin' (type 'KspTaskJvm').
  - Gradle detected a problem with the following location: '/Users/Developer/StudioProjects/mobilebank-android/app/build/generated/ksp/googleDebug'.

    Reason: Task ':app:explodeCodeSourceGoogleDebug' uses this output of task ':app:kspGoogleDebugKotlin' 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 ':app:kspGoogleDebugKotlin' as an input of ':app:explodeCodeSourceGoogleDebug'.
      2. Declare an explicit dependency on ':app:kspGoogleDebugKotlin' from ':app:explodeCodeSourceGoogleDebug' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:kspGoogleDebugKotlin' from ':app:explodeCodeSourceGoogleDebug' using Task#mustRunAfter.

For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

We can specify the dependency of the :explodeCodeSource task on :kspKotlin as follows and it will work:

allprojects.forEach { project ->
        project.tasks.withType<CodeSourceExploderTask>().configureEach {
            dependsOn(*project.tasks.withType<KspTaskJvm>().toTypedArray())
        }
}

Before bumping to 1.31.0 we used 1.25.0 and did not get the error. The error occurs on versions higher than 1.29.0.

autonomousapps commented 1 month ago

Thanks for the issue. Do you have a minimal reproducer?

Mrkchv commented 1 month ago

@autonomousapps Unfortunately I cannot share the code of our project. I also tried to make a test project, but I didn't get the error. Perhaps the logs will be useful project_health_debug_log.txt.zip

autonomousapps commented 1 month ago

My working assumption is that this is another instance of this Gradle bug, except that you say this only appears on 1.30.0 and higher. A reproducer would be very useful.