Skip to content

Commit 467e063

Browse files
committed
Merge branch '2.4.x' into 2.5.x
2 parents cf8a1b8 + 8e704aa commit 467e063

File tree

2 files changed

+65
-32
lines changed

2 files changed

+65
-32
lines changed

buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.gradle.api.artifacts.ModuleDependency;
3939
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
4040
import org.gradle.api.artifacts.dsl.DependencyHandler;
41+
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
4142
import org.gradle.api.tasks.Input;
4243
import org.gradle.api.tasks.TaskAction;
4344

@@ -48,6 +49,9 @@
4849
*/
4950
public class CheckClasspathForUnnecessaryExclusions extends DefaultTask {
5051

52+
private static final Map<String, String> SPRING_BOOT_DEPENDENCIES_PROJECT = Collections.singletonMap("path",
53+
":spring-boot-project:spring-boot-dependencies");
54+
5155
private final Map<String, Set<String>> exclusionsByDependencyId = new TreeMap<>();
5256

5357
private final Map<String, Dependency> dependencyById = new HashMap<>();
@@ -63,27 +67,31 @@ public CheckClasspathForUnnecessaryExclusions(DependencyHandler dependencyHandle
6367
ConfigurationContainer configurations) {
6468
this.dependencyHandler = getProject().getDependencies();
6569
this.configurations = getProject().getConfigurations();
66-
this.platform = this.dependencyHandler.create(this.dependencyHandler.platform(this.dependencyHandler
67-
.project(Collections.singletonMap("path", ":spring-boot-project:spring-boot-dependencies"))));
70+
this.platform = this.dependencyHandler.create(
71+
this.dependencyHandler.platform(this.dependencyHandler.project(SPRING_BOOT_DEPENDENCIES_PROJECT)));
6872
getOutputs().upToDateWhen((task) -> true);
6973
}
7074

7175
public void setClasspath(Configuration classpath) {
7276
this.exclusionsByDependencyId.clear();
7377
this.dependencyById.clear();
74-
classpath.getAllDependencies().all((dependency) -> {
75-
if (dependency instanceof ModuleDependency) {
76-
String dependencyId = dependency.getGroup() + ":" + dependency.getName();
77-
Set<ExcludeRule> excludeRules = ((ModuleDependency) dependency).getExcludeRules();
78-
TreeSet<String> exclusions = excludeRules.stream()
79-
.map((rule) -> rule.getGroup() + ":" + rule.getModule())
80-
.collect(Collectors.toCollection(TreeSet::new));
81-
this.exclusionsByDependencyId.put(dependencyId, exclusions);
82-
if (!exclusions.isEmpty()) {
83-
this.dependencyById.put(dependencyId, getProject().getDependencies().create(dependencyId));
84-
}
85-
}
86-
});
78+
classpath.getAllDependencies().all(this::processDependency);
79+
}
80+
81+
private void processDependency(Dependency dependency) {
82+
if (dependency instanceof ModuleDependency) {
83+
processDependency((ModuleDependency) dependency);
84+
}
85+
}
86+
87+
private void processDependency(ModuleDependency dependency) {
88+
String dependencyId = getId(dependency);
89+
TreeSet<String> exclusions = dependency.getExcludeRules().stream().map(this::getId)
90+
.collect(Collectors.toCollection(TreeSet::new));
91+
this.exclusionsByDependencyId.put(dependencyId, exclusions);
92+
if (!exclusions.isEmpty()) {
93+
this.dependencyById.put(dependencyId, getProject().getDependencies().create(dependencyId));
94+
}
8795
}
8896

8997
@Input
@@ -94,33 +102,55 @@ Map<String, Set<String>> getExclusionsByDependencyId() {
94102
@TaskAction
95103
public void checkForUnnecessaryExclusions() {
96104
Map<String, Set<String>> unnecessaryExclusions = new HashMap<>();
97-
for (Entry<String, Set<String>> entry : this.exclusionsByDependencyId.entrySet()) {
98-
String dependencyId = entry.getKey();
99-
Set<String> exclusions = entry.getValue();
105+
this.exclusionsByDependencyId.forEach((dependencyId, exclusions) -> {
100106
if (!exclusions.isEmpty()) {
101107
Dependency toCheck = this.dependencyById.get(dependencyId);
102108
List<String> dependencies = this.configurations.detachedConfiguration(toCheck, this.platform)
103-
.getIncoming().getArtifacts().getArtifacts().stream().map((artifact) -> {
104-
ModuleComponentIdentifier id = (ModuleComponentIdentifier) artifact.getId()
105-
.getComponentIdentifier();
106-
return id.getGroup() + ":" + id.getModule();
107-
}).collect(Collectors.toList());
109+
.getIncoming().getArtifacts().getArtifacts().stream().map(this::getId)
110+
.collect(Collectors.toList());
108111
exclusions.removeAll(dependencies);
112+
removeProfileExclusions(dependencyId, exclusions);
109113
if (!exclusions.isEmpty()) {
110114
unnecessaryExclusions.put(dependencyId, exclusions);
111115
}
112116
}
113-
}
117+
});
114118
if (!unnecessaryExclusions.isEmpty()) {
115-
StringBuilder message = new StringBuilder("Unnecessary exclusions detected:");
116-
for (Entry<String, Set<String>> entry : unnecessaryExclusions.entrySet()) {
117-
message.append(String.format("%n %s", entry.getKey()));
118-
for (String exclusion : entry.getValue()) {
119-
message.append(String.format("%n %s", exclusion));
120-
}
119+
throw new GradleException(getExceptionMessage(unnecessaryExclusions));
120+
}
121+
}
122+
123+
private void removeProfileExclusions(String dependencyId, Set<String> exclusions) {
124+
if ("org.xmlunit:xmlunit-core".equals(dependencyId)) {
125+
exclusions.remove("javax.xml.bind:jaxb-api");
126+
}
127+
}
128+
129+
private String getExceptionMessage(Map<String, Set<String>> unnecessaryExclusions) {
130+
StringBuilder message = new StringBuilder("Unnecessary exclusions detected:");
131+
for (Entry<String, Set<String>> entry : unnecessaryExclusions.entrySet()) {
132+
message.append(String.format("%n %s", entry.getKey()));
133+
for (String exclusion : entry.getValue()) {
134+
message.append(String.format("%n %s", exclusion));
121135
}
122-
throw new GradleException(message.toString());
123136
}
137+
return message.toString();
138+
}
139+
140+
private String getId(ResolvedArtifactResult artifact) {
141+
return getId((ModuleComponentIdentifier) artifact.getId().getComponentIdentifier());
142+
}
143+
144+
private String getId(ModuleDependency dependency) {
145+
return dependency.getGroup() + ":" + dependency.getName();
146+
}
147+
148+
private String getId(ExcludeRule rule) {
149+
return rule.getGroup() + ":" + rule.getModule();
150+
}
151+
152+
private String getId(ModuleComponentIdentifier identifier) {
153+
return identifier.getGroup() + ":" + identifier.getModule();
124154
}
125155

126156
}

spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
api(project(":spring-boot-project:spring-boot-test"))
1010
api(project(":spring-boot-project:spring-boot-test-autoconfigure"))
1111
api("com.jayway.jsonpath:json-path")
12+
api("jakarta.xml.bind:jakarta.xml.bind-api")
1213
api("org.assertj:assertj-core")
1314
api("org.hamcrest:hamcrest")
1415
api("org.junit.jupiter:junit-jupiter")
@@ -17,5 +18,7 @@ dependencies {
1718
api("org.skyscreamer:jsonassert")
1819
api("org.springframework:spring-core")
1920
api("org.springframework:spring-test")
20-
api("org.xmlunit:xmlunit-core")
21+
api("org.xmlunit:xmlunit-core") {
22+
exclude group: "javax.xml.bind", module: "jaxb-api"
23+
}
2124
}

0 commit comments

Comments
 (0)