Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions opensca/sca/java/mvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,26 @@ func parsePom(ctx context.Context, pom *Pom, getpom getPomFunc) *model.DepGraph

np.Update(dep)

// 非根pom直接引入的依赖使用当前pom的dependencyManagement补全
if np != pom {
if d, ok := depManagement[dep.Index2()]; ok {
exclusion := append(dep.Exclusions, d.Exclusions...)
// 使用当前pom的dependencyManagement补全
if d, ok := depManagement[dep.Index2()]; ok {
exclusion := append(dep.Exclusions, d.Exclusions...)
if dep.Version == "" {
dep = d
dep.Exclusions = exclusion
np.Update(dep)
}
dep.Exclusions = exclusion
np.Update(dep)
}

// 非根pom直接引入的依赖 或者组件版本号为空 需要再次使用根pom的dependencyManagement补全
if np != pom || dep.Version == "" {
d, ok := rootPomManagement[dep.Index2()]
if ok {
// exclusion 需要保留
exclusion := append(dep.Exclusions, d.Exclusions...)
originVersion := dep.Version
dep = d
if dep.Version == "" {
dep.Version = originVersion
}
dep.Exclusions = exclusion
pom.Update(dep)
}
Expand Down
48 changes: 48 additions & 0 deletions test/java/16/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>demo</artifactId>
<version>1.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dkms-gcs-sdk</artifactId>
<version>0.5.2</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
<exclusion>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dkms-gcs-openapi</artifactId>
</exclusion>
<exclusion>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dkms-gcs-openapi-util</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dkms-gcs-sdk</artifactId>
<version>0.5.2</version>
</dependency>
</dependencies>
</project>
12 changes: 12 additions & 0 deletions test/java/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ var cases = []tool.TaskCase{
),
),
)},

// 依赖的pom中DependencyManagement管理范围
{Path: "16", Result: tool.Dep("", "",
tool.Dep3("org.example", "demo", "1.0",
tool.Dep3("com.aliyun", "alibabacloud-dkms-gcs-sdk", "0.5.2",
tool.DevDep3("com.aliyun", "tea", "1.2.3"),
tool.Dep3("com.aliyun", "tea-util", "0.2.18",
tool.Dep3("com.google.code.gson", "gson", "2.8.9"),
),
),
),
)},
}

func Test_JavaWithStatic(t *testing.T) {
Expand Down