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.67k stars 115 forks source link

Plugin creates variant ambiguity errors with JVM Test Suite Plugin + Jacoco Aggregation Plugin #1159

Closed muellerml closed 2 months ago

muellerml commented 2 months ago

Plugin version 1.31.0

Gradle version 8.7

JDK version 21

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version 1.9.23

Describe the bug Applying the dependency analysis plugin creates an ambiguity variant error if Gradle 8.7 is used together with JVM Test Suite Plugin (https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html#jvm_test_suite_plugin) and Jacoco Aggregation Plugin (https://docs.gradle.org/current/userguide/jacoco_report_aggregation_plugin.html)

To Reproduce Steps to reproduce the behavior:

  1. Execute testCodeCoverageReport task from example reproducer https://github.com/muellerml/gradle-jacoco-reproducer.git without Dependency Analysis Plugin -> works fine
  2. Execute testCodeCoverageReport task from example reproducer https://github.com/muellerml/gradle-jacoco-reproducer.git with Dependency Analysis Plugin -> error
  3. Execute testCodeCoverageReport task from example reproducer https://github.com/muellerml/gradle-jacoco-reproducer.git with Dependency Analysis Plugin and downgrade to Gradle 8.6 -> works fine

Expected behavior Applying the Plugin does not influence other tasks like the testCodeCoverageReport provided by the Jacoco Aggregation Plugin

autonomousapps commented 2 months ago

Thanks for the report.

autonomousapps commented 2 months ago

For the record, here's the error:

./gradlew testCodeCoverageReport

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':testCodeCoverageReport'.
> Could not resolve all task dependencies for configuration ':aggregateCodeCoverageReportResults'.
   > The consumer was configured to find a component of category 'verification', as well as attribute 'artifactType' with value 'binary', attribute 'org.gradle.testsuite.type' with value 'unit-test', attribute 'org.gradle.verificationtype' with value 'jacoco-coverage'. However we cannot choose between the following variants of project :subproject-a:
       - projectHealthElements
       - resolvedDepsElements
     All of them match the consumer attributes:
       - Variant 'projectHealthElements' capability gradle-jacoco-reproducer:subproject-a:unspecified:
           - Unmatched attributes:
               - Doesn't say anything about artifactType (required 'binary')
               - Doesn't say anything about its component category (required a component of category 'verification')
               - Doesn't say anything about org.gradle.testsuite.type (required 'unit-test')
               - Doesn't say anything about org.gradle.verificationtype (required 'jacoco-coverage')
               - Provides attribute 'dagp.internal.artifacts' with value 'project-health' but the consumer didn't ask for it
       - Variant 'resolvedDepsElements' capability gradle-jacoco-reproducer:subproject-a:unspecified:
           - Unmatched attributes:
               - Doesn't say anything about artifactType (required 'binary')
               - Doesn't say anything about its component category (required a component of category 'verification')
               - Doesn't say anything about org.gradle.testsuite.type (required 'unit-test')
               - Doesn't say anything about org.gradle.verificationtype (required 'jacoco-coverage')
               - Provides attribute 'dagp.internal.artifacts' with value 'resolved-deps' but the consumer didn't ask for it
   > The consumer was configured to find a component of category 'verification', as well as attribute 'artifactType' with value 'binary', attribute 'org.gradle.testsuite.type' with value 'unit-test', attribute 'org.gradle.verificationtype' with value 'jacoco-coverage'. However we cannot choose between the following variants of project :subproject-b:
       - projectHealthElements
       - resolvedDepsElements
     All of them match the consumer attributes:
       - Variant 'projectHealthElements' capability gradle-jacoco-reproducer:subproject-b:unspecified:
           - Unmatched attributes:
               - Doesn't say anything about artifactType (required 'binary')
               - Doesn't say anything about its component category (required a component of category 'verification')
               - Doesn't say anything about org.gradle.testsuite.type (required 'unit-test')
               - Doesn't say anything about org.gradle.verificationtype (required 'jacoco-coverage')
               - Provides attribute 'dagp.internal.artifacts' with value 'project-health' but the consumer didn't ask for it
       - Variant 'resolvedDepsElements' capability gradle-jacoco-reproducer:subproject-b:unspecified:
           - Unmatched attributes:
               - Doesn't say anything about artifactType (required 'binary')
               - Doesn't say anything about its component category (required a component of category 'verification')
               - Doesn't say anything about org.gradle.testsuite.type (required 'unit-test')
               - Doesn't say anything about org.gradle.verificationtype (required 'jacoco-coverage')
               - Provides attribute 'dagp.internal.artifacts' with value 'resolved-deps' but the consumer didn't ask for it

And I have confirmed this error does not appear in Gradle 8.6. I wonder if it's a Gradle bug?

autonomousapps commented 2 months ago

Gradle suggests that DAGP could add a custom Category, and that should be sufficient. They are surprised it hasn't broken before now 🤔