Skip to content

Commit

Permalink
Maven standard dependencies should take precedence over managed depen…
Browse files Browse the repository at this point in the history
…dencies (#1000)

Managed dependencies are not real dependencies so they should not take
precedence over standard dependencies.

Dependency management is used to control the versions of artifacts used
in transitive dependencies.
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management

Also, version requirements in managed dependencies are only referred
when the requirement is not defined for that dependency in standard
dependencies section.
  • Loading branch information
cuixq committed May 30, 2024
1 parent e94c6b5 commit 854cb01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/lockfile/parse-maven-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ func (e MavenLockExtractor) Extract(f DepFile) ([]PackageDetails, error) {

details := map[string]PackageDetails{}

for _, lockPackage := range parsedLockfile.Dependencies {
for _, lockPackage := range parsedLockfile.ManagedDependencies {
finalName := lockPackage.GroupID + ":" + lockPackage.ArtifactID

pkgDetails := PackageDetails{
Name: finalName,
Version: lockPackage.ResolveVersion(*parsedLockfile),
Expand All @@ -137,9 +136,10 @@ func (e MavenLockExtractor) Extract(f DepFile) ([]PackageDetails, error) {
details[finalName] = pkgDetails
}

// managed dependencies take precedent over standard dependencies
for _, lockPackage := range parsedLockfile.ManagedDependencies {
// standard dependencies take precedent over managed dependencies
for _, lockPackage := range parsedLockfile.Dependencies {
finalName := lockPackage.GroupID + ":" + lockPackage.ArtifactID

pkgDetails := PackageDetails{
Name: finalName,
Version: lockPackage.ResolveVersion(*parsedLockfile),
Expand Down
2 changes: 1 addition & 1 deletion pkg/lockfile/parse-maven-lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestParseMavenLock_WithDependencyManagement(t *testing.T) {
expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "io.netty:netty-all",
Version: "4.1.42.Final",
Version: "4.1.9",
Ecosystem: lockfile.MavenEcosystem,
CompareAs: lockfile.MavenEcosystem,
},
Expand Down

0 comments on commit 854cb01

Please sign in to comment.