Skip to content

Commit 80e50d9

Browse files
authored
fix(manifest): keep Maven dependencies left under a sibling's test-jar (#1684)
A module that reaches a sibling through both its jar and its test-jar shares one node for both, but Maven can keep the sibling's dependencies under the test-jar alone. The walk visited each node once, so it skipped that subtree and the dependencies were missing from the SBOM. Key the visited set by the full coordinate instead.
1 parent 0c059e3 commit 80e50d9

9 files changed

Lines changed: 76 additions & 13 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1212
### Fixed
1313
- `--exclude-paths` patterns are now matched relative to the scan root in every build root. They now also exclude modules a build reaches outside its own directory (Maven `../` modules, relocated Gradle projects) and modules matched by wildcards that span a build-root boundary, such as `*/core`.
1414
- `--exclude-paths` patterns written with Windows `\` separators now exclude JVM build modules in single-root runs too.
15+
- Maven SBOMs keep the dependencies a module reaches through a sibling module's test-jar.
1516

1617
## [1.12.2](https://github.com/SocketDev/socket-cli/releases/tag/v1.12.2) - 2026-10-30
1718

‎src/commands/manifest/scripts/maven-extension/src/main/java/tech/coana/socket/SocketFactsRecordsEngine.java‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,12 @@ private String visit(
416416
String type = artifact.getProperty(ARTIFACT_PROPERTY_TYPE, artifact.getExtension());
417417
String classifier = artifact.getClassifier();
418418
String version = artifact.getBaseVersion();
419-
String id = internal
420-
? SocketSupport.bareId(artifact.getGroupId(), artifact.getArtifactId(), version)
421-
: externalId(artifact);
422-
423-
// One walk per node per module traversal: a shared subtree reached via another edge is already
424-
// fully recorded (node, children, resolved file), so hand back the id without re-descending.
425-
// Keeps reconverging graphs linear.
426-
if (!visited.add(id)) return id;
419+
String key = externalId(artifact);
420+
String id = internal ? SocketSupport.bareId(artifact.getGroupId(), artifact.getArtifactId(), version) : key;
421+
422+
// One walk per artifact: a shared subtree is already recorded. Keyed by coordinate, as a sibling's jar
423+
// and test-jar share a node but Maven can keep the sibling's dependencies under either.
424+
if (!visited.add(key)) return id;
427425

428426
Node node = internal
429427
? upsert(nodes, id, artifact.getGroupId(), artifact.getArtifactId(), "", "", version, gav)

‎src/commands/manifest/scripts/test/maven-compat/project/app/pom.xml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
</parent>
99
<artifactId>app</artifactId>
1010
<dependencies>
11-
<!-- internal reactor module -> inter-module edge, bare-id component -->
11+
<!-- internal reactor modules -> inter-module edges, bare-id components. lib's jar comes in
12+
through mid, deeper than lib's test-jar further down, so Maven keeps demo.ext:libdep (with
13+
its compile scope) under the test-jar node and none under the jar node, which the walk
14+
reaches first. -->
1215
<dependency>
1316
<groupId>demo</groupId>
14-
<artifactId>lib</artifactId>
17+
<artifactId>mid</artifactId>
1518
<version>1.0</version>
1619
</dependency>
1720
<!-- external prod dep (stub artifact from the generated repo, no transitive deps) -->
@@ -43,5 +46,12 @@
4346
<artifactId>conflict-prod</artifactId>
4447
<version>1.0</version>
4548
</dependency>
49+
<dependency>
50+
<groupId>demo</groupId>
51+
<artifactId>lib</artifactId>
52+
<version>1.0</version>
53+
<type>test-jar</type>
54+
<scope>test</scope>
55+
</dependency>
4656
</dependencies>
4757
</project>

‎src/commands/manifest/scripts/test/maven-compat/project/lib/pom.xml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,25 @@
77
<version>1.0</version>
88
</parent>
99
<artifactId>lib</artifactId>
10+
<dependencies>
11+
<dependency>
12+
<groupId>demo.ext</groupId>
13+
<artifactId>libdep</artifactId>
14+
<version>1.0</version>
15+
</dependency>
16+
</dependencies>
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<artifactId>maven-jar-plugin</artifactId>
21+
<executions>
22+
<execution>
23+
<goals>
24+
<goal>test-jar</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
</plugin>
29+
</plugins>
30+
</build>
1031
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>demo</groupId>
6+
<artifactId>root</artifactId>
7+
<version>1.0</version>
8+
</parent>
9+
<artifactId>mid</artifactId>
10+
<dependencies>
11+
<dependency>
12+
<groupId>demo</groupId>
13+
<artifactId>lib</artifactId>
14+
<version>1.0</version>
15+
</dependency>
16+
</dependencies>
17+
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package demo;
2+
3+
public class Mid {
4+
}

‎src/commands/manifest/scripts/test/maven-compat/project/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<packaging>pom</packaging>
88
<modules>
99
<module>lib</module>
10+
<module>mid</module>
1011
<module>app</module>
1112
</modules>
1213
<properties>

‎src/commands/manifest/scripts/test/maven-compat/smoke-test-workspaces.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ if tool != 'maven':
4545
errors.append(f"meta tool {tool!r} != 'maven'")
4646
if build_root != sys.argv[2]:
4747
errors.append(f"buildRoot {build_root!r} != {sys.argv[2]!r}")
48-
expected_build_files = {'pom.xml', 'lib/pom.xml', 'app/pom.xml'}
48+
expected_build_files = {'pom.xml', 'lib/pom.xml', 'mid/pom.xml', 'app/pom.xml'}
4949
if build_files != expected_build_files:
5050
errors.append(f"projectBuild files {sorted(build_files)} != {sorted(expected_build_files)}")
51-
expected = {'root', 'lib', 'app'}
51+
expected = {'root', 'lib', 'mid', 'app'}
5252
if set(projects) != expected:
5353
errors.append(f"expected reactor modules {sorted(expected)}, got {sorted(projects)}")
5454
for artifact in expected & set(projects):

‎src/commands/manifest/scripts/test/maven-compat/smoke-test.sh‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# inter-module edge lines up with its `project` record);
99
# - resolves a scope conflict so the retained node stays reachable from its parent root;
1010
# - every component is reachable from a direct dependency of its own root (no orphaned components);
11+
# - keeps the dependencies Maven leaves only under a sibling module's test-jar (app reaches
12+
# demo.ext:libdep under lib's test-jar node, after lib's jar node through mid);
1113
# - materializes resolved external jars under -Dsocket.withFiles;
1214
# - scopes that materialization to -Dsocket.populateFilesFor (a newline-delimited GAV file).
1315
#
@@ -36,7 +38,8 @@ bash "$HERE/../make-stub-repo.sh" "$STUBS" \
3638
'demo.ext:harness-core:1.0' \
3739
'demo.ext:conflict-test:1.0+demo.ext:shared:1.0' \
3840
'demo.ext:conflict-prod:1.0+demo.ext:shared:1.0' \
39-
'demo.ext:shared:1.0'
41+
'demo.ext:shared:1.0' \
42+
'demo.ext:libdep:1.0'
4043
# Maven's own plugin closure stays cached between runs; the stubs never do, so every run has to
4144
# resolve them from the repo just generated.
4245
rm -rf "$M2/demo" "$RECORDS" "$PROJECT"/*/target "$PROJECT"/target
@@ -52,6 +55,14 @@ echo "+ $("$MVN" -v 2>/dev/null | head -1)"
5255
compile )
5356

5457
python3 "$HERE/assert-records.py" "$RECORDS"
58+
python3 - "$RECORDS" <<'PY'
59+
import sys
60+
rows = [l.rstrip('\n').split('\t') for l in open(sys.argv[1]) if l.strip()]
61+
app = {r[1] for r in rows if r[0] == 'root' and r[2] == 'demo:app:1.0'}
62+
if not any(r[0] == 'node' and r[1] in app and r[2].startswith('demo.ext:libdep:') for r in rows):
63+
print("FAIL: demo.ext:libdep missing from app"); sys.exit(1)
64+
print("PASS: demo.ext:libdep in app through lib's test-jar")
65+
PY
5566
python3 "$HERE/../assert-reachability.py" "$RECORDS"
5667

5768
# Second run: scope --with-files to a single GAV and assert ONLY that artifact is materialized.

0 commit comments

Comments
 (0)