Skip to content

fix(remediate): cover subproject dependencies when remediating a Gradle catalog - #697

Open
Strum355 wants to merge 1 commit into
guacsec:mainfrom
Strum355:feature/TC-6900-gradle-catalog-subprojects
Open

Strum355 wants to merge 1 commit into
guacsec:mainfrom
Strum355:feature/TC-6900-gradle-catalog-subprojects

Conversation

@Strum355

@Strum355 Strum355 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Gradle remediation only supports version catalogs. The catalog target was resolved to its owning build file and analyzed with gradle dependencies, which reports only the current project. Dependencies used solely by subprojects were therefore missing from the remediation report, and a root project with no dependencies made analysis crash outright.

When the target is a *.versions.toml, now analyze every project in that catalog's build via discoverGradleSubprojects(), merge the remediations and deduplicate by purl, then apply them to the catalog through the existing TOML updater. Discovery falls back to analyzing the catalog itself when no settings file or projects are found. Dependencies that are not in the catalog are reported as skipped.

Two provider fixes made subproject analysis possible:

  • read group/name/version from gradle properties instead of requiring a Root project header, which subprojects do not emit
  • ignore non-dependency lines such as No dependencies instead of treating them as depth-1 tree entries; this also fixes empty Gradle projects and stack-batch for subproject build files

Both golden fixtures were checked against real Gradle 8.14.3 output.

Implements TC-6900

Description

Describe what you did and why.

Related issues (if any):

  • fixes: #issue_number_goes_here

Checklist

  • I have followed this repository's contributing guidelines.
  • I will adhere to the project's code of conduct.

Additional information

Anything else?

Summary by Sourcery

Extend Gradle version catalog remediation to cover multi-project builds while making subproject and empty-project dependency analysis reliable.

Bug Fixes:

  • Include dependencies used exclusively by Gradle subprojects when remediating version catalogs.
  • Prevent Gradle analysis from failing for subprojects and projects with empty dependency trees.
  • Report catalog remediation dependencies that are not declared in the catalog as skipped.

Enhancements:

  • Expand Gradle catalog analysis across all discoverable projects in the owning build, deduplicate findings, and retain fallback analysis when project discovery is unavailable.

Documentation:

  • Document multi-project Gradle catalog analysis and the handling of dependencies declared outside the catalog.

Tests:

  • Add coverage for Gradle subproject analysis, empty dependency trees, catalog fan-out, deduplication, skipped dependencies, and discovery fallback.

…le catalog

Gradle remediation only supports version catalogs. The catalog target was
resolved to its owning build file and analyzed with `gradle dependencies`,
which reports only the current project. Dependencies used solely by
subprojects were therefore missing from the remediation report, and a root
project with no dependencies made analysis crash outright.

When the target is a `*.versions.toml`, now analyze every project in that
catalog's build via `discoverGradleSubprojects()`, merge the remediations and
deduplicate by purl, then apply them to the catalog through the existing TOML
updater. Discovery falls back to analyzing the catalog itself when no settings
file or projects are found. Dependencies that are not in the catalog are
reported as skipped.

Two provider fixes made subproject analysis possible:
- read group/name/version from `gradle properties` instead of requiring a
  `Root project` header, which subprojects do not emit
- ignore non-dependency lines such as `No dependencies` instead of treating
  them as depth-1 tree entries; this also fixes empty Gradle projects and
  `stack-batch` for subproject build files

Both golden fixtures were checked against real Gradle 8.14.3 output.

Implements TC-6900

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Strum355
Strum355 requested review from a-oren and ruromero November 16, 2026 12:45
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Analyze every project in a Gradle catalog’s build, merge and deduplicate findings, and use the existing TOML updater; fall back when project discovery fails and distinguish catalog omissions in skipped results.

  • src/remediate.js L207-233, L320-342 (+2 small edits)

Support subproject analysis by sharing bounded build-file discovery, parsing project identity from Gradle properties, and filtering non-dependency output from dependency trees.

  • src/providers/java_gradle.js L43-64, L295-309 (+6 small edits)

Documentation

Document that catalog remediation includes dependencies used in subprojects and that directly declared Gradle DSL dependencies are skipped.

  • README.md L866, L946

Tests

Add provider fixtures and coverage for subproject and empty dependency-tree output, and test catalog fan-out, deduplication, skipped dependencies, and fallback behavior.

  • test/providers/java_gradle_groovy.test.js L142-161
  • test/providers/tst_manifests/gradle/empty_dependencies/build.gradle L1-8
  • test/providers/tst_manifests/gradle/empty_dependencies/depTree.txt L1-8
  • test/providers/tst_manifests/gradle/empty_dependencies/expected_stack_sbom.json L1-27
  • test/providers/tst_manifests/gradle/empty_dependencies/gradle.properties L1-11
  • test/providers/tst_manifests/gradle/gradle_multi_project/app/build.gradle L1-11
  • test/providers/tst_manifests/gradle/gradle_multi_project/app/depTree.txt L1-10
  • test/providers/tst_manifests/gradle/gradle_multi_project/app/expected_stack_sbom.json L1-62
  • test/providers/tst_manifests/gradle/gradle_multi_project/app/gradle.properties L1-11
  • test/remediate.test.js L133-136, L281-381 (+2 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 7 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/remediate.js" line_range="230" />
<code_context>
+		return [manifestPath]
+	}
+
+	const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts)
+	return projects.length > 0 ? projects : [manifestPath]
+}
</code_context>
<issue_to_address>
**Subproject dependencies go unreported**

When a settings-included subproject has no local build file, or Gradle project listing fails while a root build file exists, `discoverGradleSubprojects()` returns only projects with their own build files, and `analysisPathsFor()` treats a nonempty result as complete; when listing fails, it likewise falls back to the root manifest. Dependencies configured for omitted subprojects never reach analysis, so the remediation report misses them.

Discover and analyze every settings-included project, including projects without local build files, and ensure a failed project listing does not silently reduce analysis to the root.

Also at `README.md:866`, `src/remediate.js:231`.
</issue_to_address>

### Comment 2
<location path="src/remediate.js" line_range="325-342" />
<code_context>
+		/** @type {Map<string, import('./remediation.js').Remediation>} */
</code_context>
<issue_to_address>
**Conflicting remediation details disappear**

When analyses report different fixed versions, vulnerability details, or recommendations for the same dependency PURL, `remediationsByPurl` keeps the first remediation and discards later reports, so project discovery order determines the fix and the merged remediation omits details from other projects; the catalog can remain vulnerable and callers receive incomplete results.

Merge or resolve all remediations for each PURL across project reports instead of retaining only the first.
</issue_to_address>

### Comment 3
<location path="src/remediate.js" line_range="225" />
<code_context>
+		return [manifestPath]
+	}
+
+	const buildFile = findNearestBuildFile(path.dirname(manifestPath))
+	if (!buildFile) {
+		return [manifestPath]
</code_context>
<issue_to_address>
**Sibling dependencies go unreported**

When a version catalog is stored beneath a subproject that has its own build file while the build settings file is in an ancestor directory, `findNearestBuildFile()` selects the subproject build file, so `analysisPathsFor()` starts discovery in that subproject and cannot find the ancestor settings file. Discovery falls back to the catalog or analyzes only that subproject, leaving sibling-project dependencies out of the report.

Find the build and settings context that owns the catalog before discovering projects, rather than starting from the nearest subproject build file.

Also at `src/remediate.js:230`.
</issue_to_address>

### Comment 4
<location path="src/remediate.js" line_range="335" />
<code_context>
-		const extracted = extractRemediations(analysisReport, {
-			providerPriority: providers ? providers.split(',').map(p => p.trim()).filter(Boolean) : undefined,
-		})
+			const analysisReport = await analysis.requestStack(provider, analysisPath, url, false, opts)
+			for (const remediation of extractRemediations(analysisReport, { providerPriority })) {
+				if (!remediationsByPurl.has(remediation.purl)) {
</code_context>
<issue_to_address>
**Catalog audit metadata is replaced**

When a version catalog is analyzed through the new project fan-out, `analysis.requestStack()` receives each project build file, so it encodes that file as the source manifest and labels it `build.gradle` or `build.gradle.kts`; the backend receives no version-catalog content for the catalog remediation request.

Preserve the catalog path and content as the audit manifest while separately selecting the project build file used to generate each project's SBOM.
</issue_to_address>

### Comment 5
<location path="src/remediate.js" line_range="225-228" />
<code_context>
+		return [manifestPath]
+	}
+
+	const buildFile = findNearestBuildFile(path.dirname(manifestPath))
+	if (!buildFile) {
+		return [manifestPath]
+	}
+
+	const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts)
</code_context>
<issue_to_address>
**Catalog fallback is silently skipped**

When a target catalog has no nearby Gradle build file, `analysisPathsFor` returns the catalog path when no build file is found, but `match` rejects that path because the Gradle provider requires a nearby build file. The catch then skips it, so remediation returns no results instead of performing the advertised fallback or reporting that analysis is impossible.

Do not route the catalog through provider matching in this state; either report the missing build as an error or implement a fallback that can actually analyze it.

Also at `src/remediate.js:329-333`.
</issue_to_address>

### Comment 6
<location path="src/remediate.js" line_range="230" />
<code_context>
+		return [manifestPath]
+	}
+
+	const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts)
+	return projects.length > 0 ? projects : [manifestPath]
+}
</code_context>
<issue_to_address>
**Gradle discovery can block remediation**

When gradle configuration or plugin resolution stalls while listing projects, `discoverGradleSubprojects` runs Gradle synchronously before analysis, and `invokeCommand` has no timeout. A Gradle configuration or plugin-resolution process that stalls therefore blocks `runRemediation` indefinitely before it can return a report.

Run project discovery with a bounded timeout and surface a clear failure rather than waiting indefinitely.
</issue_to_address>

### Comment 7
<location path="test/remediate.test.js" line_range="332" />
<code_context>
+		test('reports a dependency found in several projects once', async () => {
+			const { tomlPath, cleanup } = createMultiProject()
+			try {
+				requestStackStub.resolves(SUBPROJECT_REPORT)
+
+				const result = await runRemediation(tomlPath, { dryRun: true })
</code_context>
<issue_to_address>
**Subproject findings go unverified**

When the fan-out implementation is broken or analyzes only the root project, when `runRemediation` analyzes only the root project, `requestStackStub.resolves(...)` still supplies the subproject report. The tests `reports a dependency found in several projects once` (lines 329–336) and `reports a subproject dependency absent from the catalog as skipped` (lines 343–357) can therefore pass without analyzing any subproject.

Make the report stubs return the relevant findings only for a subproject path, and assert that the subproject was analyzed.

Also at `test/remediate.test.js:346`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 7 findings to address first, and a remediation found only in a Gradle subproject can now cause the shared version catalog to be updated. If the analysis selects the wrong version, that value remains in the catalog after this code is reverted, but it can be corrected or reverted in the manifest.

Blocking findings: src/remediate.js:230, src/remediate.js:342, src/remediate.js:225, src/remediate.js:335, src/remediate.js:228, and 2 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/remediate.js
return [manifestPath]
}

const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Subproject dependencies go unreported

When a settings-included subproject has no local build file, or Gradle project listing fails while a root build file exists, discoverGradleSubprojects() returns only projects with their own build files, and analysisPathsFor() treats a nonempty result as complete; when listing fails, it likewise falls back to the root manifest. Dependencies configured for omitted subprojects never reach analysis, so the remediation report misses them.

Discover and analyze every settings-included project, including projects without local build files, and ensure a failed project listing does not silently reduce analysis to the root.

Also at README.md:866, src/remediate.js:231.

Prompt for AI agents
In `src/remediate.js` at line 230:

**Subproject dependencies go unreported**

When a settings-included subproject has no local build file, or Gradle project listing fails while a root build file exists, `discoverGradleSubprojects()` returns only projects with their own build files, and `analysisPathsFor()` treats a nonempty result as complete; when listing fails, it likewise falls back to the root manifest. Dependencies configured for omitted subprojects never reach analysis, so the remediation report misses them.

Discover and analyze every settings-included project, including projects without local build files, and ensure a failed project listing does not silently reduce analysis to the root.

Also at `README.md:866`, `src/remediate.js:231`.

Comment thread src/remediate.js
Comment on lines +325 to +342
/** @type {Map<string, import('./remediation.js').Remediation>} */
const remediationsByPurl = new Map()
for (const analysisPath of analysisPaths) {
let provider
try {
provider = match(analysisPath, availableProviders, opts)
} catch {
continue
}

const analysisReport = await analysis.requestStack(provider, manifestPath, url, false, opts)
const extracted = extractRemediations(analysisReport, {
providerPriority: providers ? providers.split(',').map(p => p.trim()).filter(Boolean) : undefined,
})
const analysisReport = await analysis.requestStack(provider, analysisPath, url, false, opts)
for (const remediation of extractRemediations(analysisReport, { providerPriority })) {
if (!remediationsByPurl.has(remediation.purl)) {
remediationsByPurl.set(remediation.purl, remediation)
}
}
}
const extracted = [...remediationsByPurl.values()].sort((a, b) => a.purl.localeCompare(b.purl))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Conflicting remediation details disappear

When analyses report different fixed versions, vulnerability details, or recommendations for the same dependency PURL, remediationsByPurl keeps the first remediation and discards later reports, so project discovery order determines the fix and the merged remediation omits details from other projects; the catalog can remain vulnerable and callers receive incomplete results.

Merge or resolve all remediations for each PURL across project reports instead of retaining only the first.

Prompt for AI agents
In `src/remediate.js` at lines 325-342:

**Conflicting remediation details disappear**

When analyses report different fixed versions, vulnerability details, or recommendations for the same dependency PURL, `remediationsByPurl` keeps the first remediation and discards later reports, so project discovery order determines the fix and the merged remediation omits details from other projects; the catalog can remain vulnerable and callers receive incomplete results.

Merge or resolve all remediations for each PURL across project reports instead of retaining only the first.

Comment thread src/remediate.js
return [manifestPath]
}

const buildFile = findNearestBuildFile(path.dirname(manifestPath))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Sibling dependencies go unreported

When a version catalog is stored beneath a subproject that has its own build file while the build settings file is in an ancestor directory, findNearestBuildFile() selects the subproject build file, so analysisPathsFor() starts discovery in that subproject and cannot find the ancestor settings file. Discovery falls back to the catalog or analyzes only that subproject, leaving sibling-project dependencies out of the report.

Find the build and settings context that owns the catalog before discovering projects, rather than starting from the nearest subproject build file.

Also at src/remediate.js:230.

Prompt for AI agents
In `src/remediate.js` at line 225:

**Sibling dependencies go unreported**

When a version catalog is stored beneath a subproject that has its own build file while the build settings file is in an ancestor directory, `findNearestBuildFile()` selects the subproject build file, so `analysisPathsFor()` starts discovery in that subproject and cannot find the ancestor settings file. Discovery falls back to the catalog or analyzes only that subproject, leaving sibling-project dependencies out of the report.

Find the build and settings context that owns the catalog before discovering projects, rather than starting from the nearest subproject build file.

Also at `src/remediate.js:230`.

Comment thread src/remediate.js
const extracted = extractRemediations(analysisReport, {
providerPriority: providers ? providers.split(',').map(p => p.trim()).filter(Boolean) : undefined,
})
const analysisReport = await analysis.requestStack(provider, analysisPath, url, false, opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Catalog audit metadata is replaced

When a version catalog is analyzed through the new project fan-out, analysis.requestStack() receives each project build file, so it encodes that file as the source manifest and labels it build.gradle or build.gradle.kts; the backend receives no version-catalog content for the catalog remediation request.

Preserve the catalog path and content as the audit manifest while separately selecting the project build file used to generate each project's SBOM.

Prompt for AI agents
In `src/remediate.js` at line 335:

**Catalog audit metadata is replaced**

When a version catalog is analyzed through the new project fan-out, `analysis.requestStack()` receives each project build file, so it encodes that file as the source manifest and labels it `build.gradle` or `build.gradle.kts`; the backend receives no version-catalog content for the catalog remediation request.

Preserve the catalog path and content as the audit manifest while separately selecting the project build file used to generate each project's SBOM.

Comment thread src/remediate.js
Comment on lines +225 to +228
const buildFile = findNearestBuildFile(path.dirname(manifestPath))
if (!buildFile) {
return [manifestPath]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Catalog fallback is silently skipped

When a target catalog has no nearby Gradle build file, analysisPathsFor returns the catalog path when no build file is found, but match rejects that path because the Gradle provider requires a nearby build file. The catch then skips it, so remediation returns no results instead of performing the advertised fallback or reporting that analysis is impossible.

Do not route the catalog through provider matching in this state; either report the missing build as an error or implement a fallback that can actually analyze it.

Also at src/remediate.js:329-333.

Prompt for AI agents
In `src/remediate.js` at lines 225-228:

**Catalog fallback is silently skipped**

When a target catalog has no nearby Gradle build file, `analysisPathsFor` returns the catalog path when no build file is found, but `match` rejects that path because the Gradle provider requires a nearby build file. The catch then skips it, so remediation returns no results instead of performing the advertised fallback or reporting that analysis is impossible.

Do not route the catalog through provider matching in this state; either report the missing build as an error or implement a fallback that can actually analyze it.

Also at `src/remediate.js:329-333`.

Comment thread src/remediate.js
return [manifestPath]
}

const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Gradle discovery can block remediation

When gradle configuration or plugin resolution stalls while listing projects, discoverGradleSubprojects runs Gradle synchronously before analysis, and invokeCommand has no timeout. A Gradle configuration or plugin-resolution process that stalls therefore blocks runRemediation indefinitely before it can return a report.

Run project discovery with a bounded timeout and surface a clear failure rather than waiting indefinitely.

Prompt for AI agents
In `src/remediate.js` at line 230:

**Gradle discovery can block remediation**

When gradle configuration or plugin resolution stalls while listing projects, `discoverGradleSubprojects` runs Gradle synchronously before analysis, and `invokeCommand` has no timeout. A Gradle configuration or plugin-resolution process that stalls therefore blocks `runRemediation` indefinitely before it can return a report.

Run project discovery with a bounded timeout and surface a clear failure rather than waiting indefinitely.

Comment thread test/remediate.test.js
test('reports a dependency found in several projects once', async () => {
const { tomlPath, cleanup } = createMultiProject()
try {
requestStackStub.resolves(SUBPROJECT_REPORT)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Subproject findings go unverified

When the fan-out implementation is broken or analyzes only the root project, when runRemediation analyzes only the root project, requestStackStub.resolves(...) still supplies the subproject report. The tests reports a dependency found in several projects once (lines 329–336) and reports a subproject dependency absent from the catalog as skipped (lines 343–357) can therefore pass without analyzing any subproject.

Make the report stubs return the relevant findings only for a subproject path, and assert that the subproject was analyzed.

Also at test/remediate.test.js:346.

Prompt for AI agents
In `test/remediate.test.js` at line 332:

**Subproject findings go unverified**

When the fan-out implementation is broken or analyzes only the root project, when `runRemediation` analyzes only the root project, `requestStackStub.resolves(...)` still supplies the subproject report. The tests `reports a dependency found in several projects once` (lines 329–336) and `reports a subproject dependency absent from the catalog as skipped` (lines 343–357) can therefore pass without analyzing any subproject.

Make the report stubs return the relevant findings only for a subproject path, and assert that the subproject was analyzed.

Also at `test/remediate.test.js:346`.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.90722% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.64%. Comparing base (ce9658d) to head (ca3a598).

Files with missing lines Patch % Lines
src/remediate.js 96.22% 2 Missing ⚠️
src/providers/java_gradle.js 97.72% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #697      +/-   ##
==========================================
+ Coverage   91.60%   91.64%   +0.04%     
==========================================
  Files          44       44              
  Lines       11638    11676      +38     
  Branches     2346     2361      +15     
==========================================
+ Hits        10661    10701      +40     
+ Misses        977      975       -2     
Flag Coverage Δ
unit-tests 91.64% <96.90%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/providers/java_gradle.js 94.73% <97.72%> (+0.21%) ⬆️
src/remediate.js 95.66% <96.22%> (+0.43%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants