dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

False positive with new style gradle test suite definition

Open gregallen opened this issue 1 year ago • 3 comments

Build scan link

Plugin version 2.0.2

Gradle version 8.10.1

JDK version 17

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

(Optional) Android Gradle Plugin (AGP) version NA

(Optional) reason output for bugs relating to incorrect advice warns junit -jupiter not needed at by testImplementation, but that dep is not explicitly present, nor is it shown by depedency-tree output.

Advice for root project
Unused dependencies which should be removed:
   testImplementation 'org junit jupiter: junit-jupiter:5.11.0'

Describe the bug Gradle now offers "suite" concept for configuring junit with

testing {
  suites {
     configureEach {
      useJunitJupiter(junitVersion)

**To Reproduce**
Steps to reproduce the behavior:
1. ... run buildHealth

**Expected behavior**
health passes

**Additional context**
<!-- Add any other context about the problem here. -->

gregallen avatar Sep 24 '24 10:09 gregallen

The plugin doesn't currently have any support for the jvm test suites stuff.

autonomousapps avatar Oct 11 '24 00:10 autonomousapps

Duplicates https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1273

autonomousapps avatar Oct 15 '24 17:10 autonomousapps

Do you have a minimal reproducer?

autonomousapps avatar Oct 15 '24 17:10 autonomousapps

Here's one - not 100% minimal (uses Kotlin not Java) but otherwise as small as it can get: https://github.com/3flex/dagp-1269

Applying useJunitJupiter() in a test suite just adds org.junit.jupiter:junit-jupiter to testImplementation and org.junit.platform:junit-platform-launcher to testRuntimeOnly, taking care of setting up the test engine for the user (Configuring Test Engines)

This is fine as far as it goes, but org.junit.jupiter:junit-jupiter does nothing except depend on junit-jupiter-api and junit-jupiter-params on testCompileClasspath as described here: https://docs.junit.org/current/user-guide/#dependency-metadata-junit-jupiter

So DAGP complains because there's no code in junit-jupiter therefore it's an unused dependency, but that's what Gradle adds automatically to testImplementation. DAGP wants the transitive dependencies e.g. junit-jupiter-api to be explicitly declared.

I don't think DAGP is wrong per se. Seems like dependency bundles are intended for this kind of thing?

dependencyAnalysis {
    structure {
        bundle("junit-jupiter") {
            includeDependency("org.junit.jupiter:junit-jupiter")
            includeDependency("org.junit.jupiter:junit-jupiter-api")
            includeDependency("org.junit.jupiter:junit-jupiter-params")
        }
    }
}

3flex avatar Aug 02 '25 05:08 3flex