Repository navigation
Description
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.debugUnitTestRuntimeClasspathorfreeReleaseAndroidTestCompileClasspath.
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
UnitTestandAndroidTestsuffixes are AGP constants for test components (isForTesting = true), seeComponentType.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 containingTest(e.g. a product flavorabTest→abTestReleaseRuntimeClasspath) don't match. - A broader rule (any camelCase word
testin 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 (
integrationTestRuntimeClasspathetc.) — their names are user-defined; - Kotlin Multiplatform (
jvmTestRuntimeClasspathetc.); - build tool configurations (
debugUnitTestLintChecksClasspath,kotlinCompilerPluginClasspathDebugUnitTest,androidLintTooletc.) andandroidTest*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
ScreenshotTestshould 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
Shaamak commentedon Nov 24, 2026
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 theqaUnitTestcase does happen. I'd suggest one extra check that rules it out.Setup: one app module with product flavors
free/paid, build typesdebug,releaseandqaUnitTest, anddependencyLocking { lockAllConfigurations() }. Lockfiles were generated withgradle :app:dependencies --write-locksusing:com.android.compose.screenshot0.0.1-alpha16 (for ScreenshotTest)On both lockfiles, Trivy v0.76.2 reports
junit:junitandespresso-corewithout--include-dev-deps.1. Configuration names in AGP 8.x and 9.x
Confirmed:
<variant>UnitTest…and<variant>AndroidTest…, for examplefreeDebugUnitTestRuntimeClasspathandpaidDebugAndroidTestCompileClasspath.One difference matters: AGP 9 adds
<variant>UnitTestLintChecksClasspathand<variant>AndroidTestLintChecksClasspath, and test dependencies are listed there too:Because a dependency is dev only if all its configurations are test ones, the fix would have no effect on AGP 9 unless
LintChecksClasspathis 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
androidTestortest(AbstractVariantInputManager.checkName), so a build type namedqaUnitTestis accepted by both AGP 8.13.2 and 9.5.2. Its production configurations then match the pattern:With the pattern alone,
commons-textwould 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>UnitTestRuntimeClasspathalways comes with the tested variant's<V>RuntimeClasspathand<V>CompileClasspath, either in a dependency line or inempty=. ForfreeQaUnitTestRuntimeClasspath,Vwould befreeQa, and there is nofreeQaRuntimeClasspath.The name can't be ambiguous: with both
qaandqaUnitTestbuild types, AGP fails withCannot add task 'assembleFreeQaUnitTest' as a task with that name already exists.So I'd propose: a configuration is a test one if
test(as now), or<V>(UnitTest|AndroidTest)<classpath>, and<V>RuntimeClasspathor<V>CompileClasspathis 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.screenshotTestImplementationdependencies are listed only there. It'sisForTesting = trueinComponentType.ktand 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-locksrun: no. Production dependencies are also listed under the variant's production configurations. With a version conflict (gson2.10.1 inimplementation, 2.11.0 intestImplementation), 2.10.1 stays in the production configurations, and only 2.11.0, which only unit tests use, is listed underUnitTestconfigurations.It can happen with a partial run. Starting without a lockfile,
gradle :app:dependencies --configuration freeDebugUnitTestRuntimeClasspath --write-lockswrites only that configuration:The same is already true for
testRuntimeClasspathtoday. For Android, the tested-variant check from point 2 covers it:freeDebugRuntimeClasspathisn'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 examplecom.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.
[-]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[/+]fix(java): mark Android test configurations as dev in gradle.lockfile