Skip to content

feat(java): mark dependencies from Android test configurations in gradle.lockfile as dev #11728

Backlog

Description

@DmitriyLewen

Description

The gradle.lockfile parser (pkg/dependency/parser/gradle/lockfile/parse.go) marks a dependency as dev only if all its configurations start with test.
This rule was added in #8803 for testCompileClasspath and testRuntimeClasspath.

The Android Gradle plugin (AGP) names the configurations of test components after the build variant, for example debugUnitTestRuntimeClasspath and debugAndroidTestCompileClasspath.
These names don't start with test, so dependencies used only in Android tests are treated as production and are reported without --include-dev-deps.

Reproduced on v0.76.2:

junit:junit:4.12=debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
empty=

trivy fs --scanners vuln . reports CVE-2020-15250 for junit:junit, while the same dependency in testCompileClasspath,testRuntimeClasspath has no findings.

Discussed in #11721.

Scope

A configuration is treated as a test one if:

  • it starts with test (as now);
  • or its whole name matches the pattern <variant>(UnitTest|AndroidTest)(CompileClasspath|RuntimeClasspath|AnnotationProcessorClasspath), e.g. debugUnitTestRuntimeClasspath or freeReleaseAndroidTestCompileClasspath.

The rule "a dependency is dev only if all its configurations are test ones" doesn't change.

Why the scope is limited

Errors in the two directions don't cost the same.
If a test dependency is treated as production, it's an extra finding.
If a production dependency is wrongly marked as dev, it's hidden by default, and its vulnerabilities silently disappear from the results.
So the rule must only match names that definitely belong to tests.

  • The UnitTest and AndroidTest suffixes are AGP constants for test components (isForTesting = true), see ComponentType.kt.
  • The pattern is anchored to the start and the end of the name: the classpath type comes right after the suffix.
    This way, user-defined names containing Test (e.g. a product flavor abTest → abTestReleaseRuntimeClasspath) don't match.
  • A broader rule (any camelCase word test in the name) would affect user-defined names, so we don't use it.

Out of scope (such dependencies stay production, as now):

  • JVM Test Suite suites (integrationTestRuntimeClasspath etc.) — their names are user-defined;
  • Kotlin Multiplatform (jvmTestRuntimeClasspath etc.);
  • build tool configurations (debugUnitTestLintChecksClasspath, kotlinCompilerPluginClasspathDebugUnitTest, androidLintTool etc.) and androidTest*DependenciesMetadata.

Please double-check before implementing

The conclusions above are based on the AGP sources and one real Android lockfile.
Please double-check them before implementing and share the results in this issue:

  • that AGP 8.x and 9.x actually name test component configurations by the <variant>(UnitTest|AndroidTest)<classpath> pattern (e.g. using the lockfile of a generated project);
  • that a variant, build type or product flavor name can't make a production configuration match this pattern (e.g. a build type qaUnitTest), or that such cases don't occur in practice;
  • whether ScreenshotTest should be included (it's also an AGP test component, but experimental);
  • that with a regular dependency locking setup, a production dependency can't end up in the lockfile only under test configurations.

If any of this doesn't hold, let's discuss the scope here before implementing.

Activity

  1. Shaamak commented on Nov 24, 2026

    @Shaamak

    I'd like to work on this. I checked the points from the description with generated projects; results are below.

    Short version: the naming is confirmed, but AGP 9 also needs LintChecksClasspath, and the qaUnitTest case does happen. I'd suggest one extra check that rules it out.

    Setup: one app module with product flavors free/paid, build types debug, release and qaUnitTest, and dependencyLocking { lockAllConfigurations() }. Lockfiles were generated with gradle :app:dependencies --write-locks using:

    • AGP 8.13.2 + Gradle 8.14.8
    • AGP 9.5.2 + Gradle 9.9.2
    • AGP 9.5.2 + com.android.compose.screenshot 0.0.1-alpha16 (for ScreenshotTest)
    implementation 'androidx.core:core:1.13.1'
    implementation 'com.google.code.gson:gson:2.10.1'
    qaUnitTestImplementation 'org.apache.commons:commons-text:1.9'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'com.google.code.gson:gson:2.11.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'

    On both lockfiles, Trivy v0.76.2 reports junit:junit and espresso-core without --include-dev-deps.

    1. Configuration names in AGP 8.x and 9.x

    Confirmed: <variant>UnitTest… and <variant>AndroidTest…, for example freeDebugUnitTestRuntimeClasspath and paidDebugAndroidTestCompileClasspath.

    One difference matters: AGP 9 adds <variant>UnitTestLintChecksClasspath and <variant>AndroidTestLintChecksClasspath, and test dependencies are listed there too:

    junit:junit:4.13.2=freeDebugAndroidTestCompileClasspath,freeDebugAndroidTestLintChecksClasspath,freeDebugAndroidTestRuntimeClasspath,freeDebugUnitTestCompileClasspath,freeDebugUnitTestLintChecksClasspath,freeDebugUnitTestRuntimeClasspath,...
    

    Because a dependency is dev only if all its configurations are test ones, the fix would have no effect on AGP 9 unless LintChecksClasspath is one of the classpath types. So I'd use (CompileClasspath|RuntimeClasspath|AnnotationProcessorClasspath|LintChecksClasspath).

    The other new AGP 9 configurations (*DependenciesMetadata, kotlinCompilerPluginClasspath*) didn't contain test dependencies in these projects.

    2. Can a variant name make a production configuration match?

    Yes. AGP only rejects build type and flavor names that start with androidTest or test (AbstractVariantInputManager.checkName), so a build type named qaUnitTest is accepted by both AGP 8.13.2 and 9.5.2. Its production configurations then match the pattern:

    org.apache.commons:commons-text:1.9=freeQaUnitTestCompileClasspath,freeQaUnitTestRuntimeClasspath,...
    

    With the pattern alone, commons-text would be marked dev and CVE-2022-42889 would be hidden.

    The two cases can be told apart using the lockfile itself. A test component configuration <V>UnitTestRuntimeClasspath always comes with the tested variant's <V>RuntimeClasspath and <V>CompileClasspath, either in a dependency line or in empty=. For freeQaUnitTestRuntimeClasspath, V would be freeQa, and there is no freeQaRuntimeClasspath.

    The name can't be ambiguous: with both qa and qaUnitTest build types, AGP fails with Cannot add task 'assembleFreeQaUnitTest' as a task with that name already exists.

    So I'd propose: a configuration is a test one if

    • it starts with test (as now), or
    • it is <V>(UnitTest|AndroidTest)<classpath>, and <V>RuntimeClasspath or <V>CompileClasspath is in the lockfile.

    If the tested variant isn't found, the configuration stays production, so any mistakes go in the safe direction.

    3. ScreenshotTest

    It uses the same naming: debugScreenshotTest{Compile,Runtime,AnnotationProcessor,LintChecks}Classpath. screenshotTestImplementation dependencies are listed only there. It's isForTesting = true in ComponentType.kt and can only be turned on with an experimental flag. Since it fits the same rule, I'd include it, but I'm fine leaving it out.

    4. Can a production dependency end up only under test configurations?

    With lockAllConfigurations() and a full --write-locks run: no. Production dependencies are also listed under the variant's production configurations. With a version conflict (gson 2.10.1 in implementation, 2.11.0 in testImplementation), 2.10.1 stays in the production configurations, and only 2.11.0, which only unit tests use, is listed under UnitTest configurations.

    It can happen with a partial run. Starting without a lockfile, gradle :app:dependencies --configuration freeDebugUnitTestRuntimeClasspath --write-locks writes only that configuration:

    androidx.core:core:1.13.1=freeDebugUnitTestRuntimeClasspath
    junit:junit:4.13.2=freeDebugUnitTestRuntimeClasspath
    empty=
    

    The same is already true for testRuntimeClasspath today. For Android, the tested-variant check from point 2 covers it: freeDebugRuntimeClasspath isn't in the file, so nothing is marked dev. If a lockfile already exists, Gradle keeps the entries for configurations that weren't resolved.

    Out of scope, for reference

    Dependencies that appear only in AGP's own tool configurations (androidLintTool, kotlinCompilerClasspath, _internal-unified-test-platform-*, unified-test-platform-gradle-work-action) are also reported as production. That's 87 packages in the AGP 9 project, for example com.android.tools.build:manifest-merger. It isn't related to tests, so I've left it out of this issue.

    If this approach sounds good, I'll open a PR with tests built from these lockfiles.

  2. changed the title [-]fix(java): mark dependencies from Android test configurations in gradle.lockfile as dev[/-] [+]feat(java): mark dependencies from Android test configurations in gradle.lockfile as dev[/+] on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions