Skip to content

Commit 87dd039

Browse files
committed
Merge branch '3.4.x'
Closes gh-44889
2 parents 5bab52d + aa6d2f1 commit 87dd039

File tree

4 files changed

+33
-85
lines changed

4 files changed

+33
-85
lines changed

buildSrc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}")
4040
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
4141
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
42-
implementation("org.apache.maven:maven-embedder:${mavenVersion}")
42+
implementation("org.apache.maven:maven-artifact:${mavenVersion}")
4343
implementation("org.antora:gradle-antora-plugin:1.0.0")
4444
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
4545
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}")

buildSrc/src/main/java/org/springframework/boot/build/MavenPublishingConventions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.boot.build;
1818

19-
import org.apache.maven.artifact.repository.MavenArtifactRepository;
2019
import org.gradle.api.Project;
20+
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
2121
import org.gradle.api.attributes.Usage;
2222
import org.gradle.api.plugins.JavaPlugin;
2323
import org.gradle.api.plugins.JavaPluginExtension;

buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java

+29-81
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,18 @@
1717
package org.springframework.boot.build.mavenplugin;
1818

1919
import java.io.File;
20-
import java.io.FileInputStream;
2120
import java.io.FileWriter;
2221
import java.io.IOException;
23-
import java.io.InputStream;
2422
import java.io.Writer;
2523
import java.nio.charset.StandardCharsets;
2624
import java.nio.file.Files;
2725
import java.nio.file.Path;
2826
import java.nio.file.StandardCopyOption;
2927
import java.util.Arrays;
3028
import java.util.Properties;
31-
import java.util.function.BiConsumer;
29+
import java.util.Set;
3230

3331
import javax.inject.Inject;
34-
import javax.xml.parsers.DocumentBuilder;
35-
import javax.xml.parsers.DocumentBuilderFactory;
36-
import javax.xml.parsers.ParserConfigurationException;
37-
import javax.xml.xpath.XPath;
38-
import javax.xml.xpath.XPathConstants;
39-
import javax.xml.xpath.XPathExpressionException;
40-
import javax.xml.xpath.XPathFactory;
4132

4233
import io.spring.javaformat.formatter.FileEdit;
4334
import io.spring.javaformat.formatter.FileFormatter;
@@ -88,19 +79,18 @@
8879
import org.gradle.api.tasks.bundling.Jar;
8980
import org.gradle.api.tasks.javadoc.Javadoc;
9081
import org.gradle.external.javadoc.StandardJavadocDocletOptions;
91-
import org.w3c.dom.Document;
9282
import org.w3c.dom.Element;
9383
import org.w3c.dom.Node;
9484
import org.w3c.dom.NodeList;
95-
import org.xml.sax.SAXException;
9685

9786
import org.springframework.boot.build.DeployedPlugin;
9887
import org.springframework.boot.build.MavenRepositoryPlugin;
88+
import org.springframework.boot.build.bom.ResolvedBom;
89+
import org.springframework.boot.build.bom.ResolvedBom.ResolvedLibrary;
9990
import org.springframework.boot.build.optional.OptionalDependenciesPlugin;
10091
import org.springframework.boot.build.test.DockerTestPlugin;
10192
import org.springframework.boot.build.test.IntegrationTestPlugin;
10293
import org.springframework.core.CollectionFactory;
103-
import org.springframework.util.Assert;
10494

10595
/**
10696
* Plugin for building Spring Boot's Maven Plugin.
@@ -125,7 +115,13 @@ public void apply(Project project) {
125115
generateHelpMojoTask);
126116
addDocumentPluginGoalsTask(project, generatePluginDescriptorTask);
127117
addPrepareMavenBinariesTask(project);
128-
addExtractVersionPropertiesTask(project);
118+
TaskProvider<ExtractVersionProperties> extractVersionPropertiesTask = addExtractVersionPropertiesTask(project);
119+
project.getTasks()
120+
.named(IntegrationTestPlugin.INT_TEST_TASK_NAME)
121+
.configure((task) -> task.getInputs()
122+
.file(extractVersionPropertiesTask.map(ExtractVersionProperties::getDestination))
123+
.withPathSensitivity(PathSensitivity.RELATIVE)
124+
.withPropertyName("versionProperties"));
129125
publishOptionalDependenciesInPom(project);
130126
project.getTasks().withType(GenerateModuleMetadata.class).configureEach((task) -> task.setEnabled(false));
131127
}
@@ -335,9 +331,9 @@ private String replaceVersionPlaceholder(Project project, String input) {
335331
return input.replace("{{version}}", project.getVersion().toString());
336332
}
337333

338-
private void addExtractVersionPropertiesTask(Project project) {
339-
project.getTasks().register("extractVersionProperties", ExtractVersionProperties.class, (task) -> {
340-
task.setEffectiveBoms(project.getConfigurations().create("versionProperties"));
334+
private TaskProvider<ExtractVersionProperties> addExtractVersionPropertiesTask(Project project) {
335+
return project.getTasks().register("extractVersionProperties", ExtractVersionProperties.class, (task) -> {
336+
task.setResolvedBoms(project.getConfigurations().create("versionProperties"));
341337
task.getDestination()
342338
.set(project.getLayout()
343339
.getBuildDirectory()
@@ -466,25 +462,25 @@ public void createRepository() {
466462

467463
public abstract static class ExtractVersionProperties extends DefaultTask {
468464

469-
private FileCollection effectiveBoms;
465+
private FileCollection resolvedBoms;
470466

471467
@InputFiles
472468
@PathSensitive(PathSensitivity.RELATIVE)
473-
public FileCollection getEffectiveBoms() {
474-
return this.effectiveBoms;
469+
public FileCollection getResolvedBoms() {
470+
return this.resolvedBoms;
475471
}
476472

477-
public void setEffectiveBoms(FileCollection effectiveBoms) {
478-
this.effectiveBoms = effectiveBoms;
473+
public void setResolvedBoms(FileCollection resolvedBoms) {
474+
this.resolvedBoms = resolvedBoms;
479475
}
480476

481477
@OutputFile
482478
public abstract RegularFileProperty getDestination();
483479

484480
@TaskAction
485481
public void extractVersionProperties() {
486-
EffectiveBom effectiveBom = new EffectiveBom(this.effectiveBoms.getSingleFile());
487-
Properties versions = extractVersionProperties(effectiveBom);
482+
ResolvedBom resolvedBom = ResolvedBom.readFrom(this.resolvedBoms.getSingleFile());
483+
Properties versions = extractVersionProperties(resolvedBom);
488484
writeProperties(versions);
489485
}
490486

@@ -499,66 +495,18 @@ private void writeProperties(Properties versions) {
499495
}
500496
}
501497

502-
private Properties extractVersionProperties(EffectiveBom effectiveBom) {
498+
private Properties extractVersionProperties(ResolvedBom resolvedBom) {
503499
Properties versions = CollectionFactory.createSortedProperties(true);
504-
versions.setProperty("project.version", effectiveBom.version());
505-
effectiveBom.property("log4j2.version", versions::setProperty);
506-
effectiveBom.property("maven-jar-plugin.version", versions::setProperty);
507-
effectiveBom.property("maven-war-plugin.version", versions::setProperty);
508-
effectiveBom.property("build-helper-maven-plugin.version", versions::setProperty);
509-
effectiveBom.property("spring-framework.version", versions::setProperty);
510-
effectiveBom.property("jakarta-servlet.version", versions::setProperty);
511-
effectiveBom.property("kotlin.version", versions::setProperty);
512-
effectiveBom.property("assertj.version", versions::setProperty);
513-
effectiveBom.property("junit-jupiter.version", versions::setProperty);
514-
return versions;
515-
}
516-
517-
}
518-
519-
private static final class EffectiveBom {
520-
521-
private final Document document;
522-
523-
private final XPath xpath;
524-
525-
private EffectiveBom(File bomFile) {
526-
this.document = loadDocument(bomFile);
527-
this.xpath = XPathFactory.newInstance().newXPath();
528-
}
529-
530-
private Document loadDocument(File bomFile) {
531-
try {
532-
try (InputStream inputStream = new FileInputStream(bomFile)) {
533-
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
534-
DocumentBuilder builder = builderFactory.newDocumentBuilder();
535-
return builder.parse(inputStream);
500+
versions.setProperty("project.version", resolvedBom.id().version());
501+
Set<String> versionProperties = Set.of("log4j2.version", "maven-jar-plugin.version",
502+
"maven-war-plugin.version", "build-helper-maven-plugin.version", "spring-framework.version",
503+
"jakarta-servlet.version", "kotlin.version", "assertj.version", "junit-jupiter.version");
504+
for (ResolvedLibrary library : resolvedBom.libraries()) {
505+
if (library.versionProperty() != null && versionProperties.contains(library.versionProperty())) {
506+
versions.setProperty(library.versionProperty(), library.version());
536507
}
537508
}
538-
catch (ParserConfigurationException | SAXException | IOException ex) {
539-
throw new IllegalStateException(ex);
540-
}
541-
}
542-
543-
private String version() {
544-
return get("version");
545-
}
546-
547-
private void property(String name, BiConsumer<String, String> handler) {
548-
handler.accept(name, get("properties/" + name));
549-
}
550-
551-
private String get(String expression) {
552-
try {
553-
Node node = (Node) this.xpath.compile("/project/" + expression)
554-
.evaluate(this.document, XPathConstants.NODE);
555-
String text = (node != null) ? node.getTextContent() : null;
556-
Assert.hasLength(text, () -> "No result for expression " + expression);
557-
return text;
558-
}
559-
catch (XPathExpressionException ex) {
560-
throw new IllegalStateException(ex);
561-
}
509+
return versions;
562510
}
563511

564512
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dependencies {
8282
mavenRepository(project(path: ":spring-boot-project:spring-boot-docker-compose", configuration: "mavenRepository"))
8383
mavenRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-parent", configuration: "mavenRepository"))
8484

85-
versionProperties(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "effectiveBom"))
85+
versionProperties(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "resolvedBom"))
8686
}
8787

8888
ext {

0 commit comments

Comments
 (0)