diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java index 21cd88849d9e..ca46468fc549 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java @@ -326,14 +326,16 @@ private NodeStatus addNewVertex(Vertex vertex, DependencyNode newPkgDep, boolean if (resolutionOptions.dumpRawGraphs()) { rawGraphBuilder.add(resolvedPkgDep); } - // Update the scope of dependencies - for (Vertex depVertex : depGraph.get(vertex)) { - DependencyNode dependencyNode = vertices.get(depVertex); - DependencyNode newDependencyNode = new DependencyNode(dependencyNode.pkgDesc(), resolvedPkgDep.scope(), - dependencyNode.resolutionType()); - vertices.put(depVertex, newDependencyNode); - if (resolutionOptions.dumpRawGraphs()) { - rawGraphBuilder.addDependency(resolvedPkgDep, newDependencyNode); + // Update the scope of dependencies only if rejected node scope is DEFAULT + if (resolvedPkgDep.scope() == PackageDependencyScope.DEFAULT) { + for (Vertex depVertex : depGraph.get(vertex)) { + DependencyNode dependencyNode = vertices.get(depVertex); + DependencyNode newDependencyNode = new DependencyNode(dependencyNode.pkgDesc(), + resolvedPkgDep.scope(), dependencyNode.resolutionType()); + vertices.put(depVertex, newDependencyNode); + if (resolutionOptions.dumpRawGraphs()) { + rawGraphBuilder.addDependency(resolvedPkgDep, newDependencyNode); + } } } }