Skip to content

fix: restore graph nodes when moduleArtifacts is empty#331

Open
adrobuta wants to merge 5 commits into
mainfrom
fix/OSM-3549
Open

fix: restore graph nodes when moduleArtifacts is empty#331
adrobuta wants to merge 5 commits into
mainfrom
fix/OSM-3549

Conversation

@adrobuta
Copy link
Copy Markdown

@adrobuta adrobuta commented Mar 30, 2026

  • Tests written and linted
  • Documentation written
  • Commit history is tidy

What this does

After PR #299 (v5 graph changes), loadGraph / loadSha1MapGraph in lib/init.gradle only created edges and recursed into d.children inside moduleArtifacts.each { ... }. When getModuleArtifacts() returned null or an empty list (common with merged default configurations, some variants, optional edges, substitution chains), the plugin skipped the node entirely and never walked children, so transitive and substituted dependencies disappeared from JSONDEPS / Gradle dep graph even though Gradle still resolved them (e.g. runtimeClasspath / dependencyInsight showed them).
This change adds a fallback path: if there are no module artifacts, emit a single logical group:artifact:jar@version node, setEdge, and recurse d.children, matching the usual default artifact shape. The same idea is applied in loadSha1MapGraph (SHA-1 keyed like the existing no-file/hash fallback).

Notes for the reviewer

How should this be manually tested?

Prerequisites: JDK 17+, network for Maven Central / Snyk API, a Snyk account/token as usual for snyk test.
Link patched plugin into the CLI (adjust paths to your checkout):

 cd /path/to/snyk-gradle-plugin
 npm pack   # produces snyk-gradle-plugin-<version>.tgz
 cd /path/to/snyk/cli   # or snyk-ls or wherever the CLI resolves the gradle plugin
 npm install /path/to/snyk-gradle-plugin/snyk-gradle-plugin-<version>.tgz

Or use whatever internal workflow you use to point the CLI at a local snyk-gradle-plugin build.
Run against the repro fixture (from repo root of this plugin, or pass absolute path):

  cd test/fixtures/spring-kafka-lz4-substitution-repro
  snyk test --file=build.gradle

What to expect (findings / counts)
Dependency count: Scan should report on the order of ~50+ Maven/Groovy dependencies (exact number can shift slightly with CLI/plugin versions; before the fix, org.lz4:lz4-java was often missing from the tested set).
Sanity: Output / dependency list should include org.lz4:lz4-java and org.apache.kafka:kafka-clients; substituted at.yawk.lz4:lz4-java should not appear as the resolved coordinate for the scan.

Screenshots

Visuals that may help the reviewer

Additional questions

@adrobuta adrobuta requested review from a team as code owners March 30, 2026 14:25
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ JamesPatrickGill
❌ adrobuta
You have signed the CLA already but the status is still pending? Let us recheck it.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Mar 30, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@adrobuta adrobuta force-pushed the fix/OSM-3549 branch 2 times, most recently from 5050968 to 9da1dc1 Compare March 30, 2026 14:43
After #299, loadGraph/loadSha1MapGraph only processed ResolvedDependency
nodes inside getModuleArtifacts(); empty lists skipped the node and never
walked d.children, dropping transitives (e.g. lz4-java) and BOM-style
nodes under merged configurations. Fall back to a single jar-shaped id and
recurse children when the artifact list is empty.
Add fixture mirroring Spring/Kafka/kafka-clients + yawk→org.lz4 substitution
and a system test that inspect() includes org.lz4:lz4-java by default scan.
adrobuta and others added 3 commits April 3, 2026 15:54
Merged firstLevelModuleDependencies can produce different ResolvedDependency
instances for the same GAV with different children. Leaving node ids in
currentChain after returning skipped later traversals and dropped transitives.
Use try/finally in loadGraph and loadSha1MapGraph.
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.

3 participants