@@ -284,6 +284,22 @@ func inheritPom(pom *Pom, getpom getPomFunc) {
284284 }
285285}
286286
287+ func replacePomDependency (old , new * PomDependency , indirect bool ) (replaced * PomDependency ) {
288+ originVersion := old .Version
289+ originScope := old .Scope
290+ dep := * new
291+ replaced = & dep
292+ // 间接依赖优先使用新的version
293+ if indirect && replaced .Version == "" {
294+ replaced .Version = originVersion
295+ }
296+ // 直接依赖优先保留原始scope
297+ if ! indirect && originScope != "" {
298+ replaced .Scope = originScope
299+ }
300+ return
301+ }
302+
287303// parsePom 解析单个pom 返回该pom的依赖图
288304func parsePom (ctx context.Context , pom * Pom , getpom getPomFunc ) * model.DepGraph {
289305
@@ -364,7 +380,7 @@ func parsePom(ctx context.Context, pom *Pom, getpom getPomFunc) *model.DepGraph
364380 if d , ok := depManagement [dep .Index2 ()]; ok {
365381 exclusion := append (dep .Exclusions , d .Exclusions ... )
366382 if dep .Version == "" {
367- dep = d
383+ dep = replacePomDependency ( dep , d , false )
368384 }
369385 dep .Exclusions = exclusion
370386 np .Update (dep )
@@ -375,11 +391,7 @@ func parsePom(ctx context.Context, pom *Pom, getpom getPomFunc) *model.DepGraph
375391 d , ok := rootPomManagement [dep .Index2 ()]
376392 if ok {
377393 exclusion := append (dep .Exclusions , d .Exclusions ... )
378- originVersion := dep .Version
379- dep = d
380- if dep .Version == "" {
381- dep .Version = originVersion
382- }
394+ dep = replacePomDependency (dep , d , true )
383395 dep .Exclusions = exclusion
384396 pom .Update (dep )
385397 }
0 commit comments