commit
59b8fb5b49
|
|
@ -9,6 +9,7 @@ plugins {
|
||||||
description = "Spring Boot Maven Plugin"
|
description = "Spring Boot Maven Plugin"
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
dependenciesBom
|
||||||
documentation
|
documentation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16,6 +17,8 @@ dependencies {
|
||||||
compileOnly("org.apache.maven.plugin-tools:maven-plugin-annotations")
|
compileOnly("org.apache.maven.plugin-tools:maven-plugin-annotations")
|
||||||
compileOnly("org.sonatype.plexus:plexus-build-api")
|
compileOnly("org.sonatype.plexus:plexus-build-api")
|
||||||
|
|
||||||
|
dependenciesBom(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "effectiveBom"))
|
||||||
|
|
||||||
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
|
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
|
||||||
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
|
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
|
||||||
implementation("org.apache.maven.shared:maven-common-artifact-filters")
|
implementation("org.apache.maven.shared:maven-common-artifact-filters")
|
||||||
|
|
@ -43,12 +46,23 @@ dependencies {
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task syncSpringBootDependenciesBom(type: Sync) {
|
||||||
|
destinationDir = file("${buildDir}/generated/sources/dependencies-bom/org/springframework/boot/maven")
|
||||||
|
from configurations.dependenciesBom
|
||||||
|
}
|
||||||
|
|
||||||
syncDocumentationSourceForAsciidoctor {
|
syncDocumentationSourceForAsciidoctor {
|
||||||
from(documentPluginGoals) {
|
from(documentPluginGoals) {
|
||||||
into "asciidoc/goals"
|
into "asciidoc/goals"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
output.dir("${buildDir}/generated/sources/dependencies-bom", builtBy: "syncSpringBootDependenciesBom")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
|
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
|
||||||
doFirst {
|
doFirst {
|
||||||
def versionEl = version.split("\\.")
|
def versionEl = version.split("\\.")
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,9 @@
|
||||||
package org.springframework.boot.maven;
|
package org.springframework.boot.maven;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.Reader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
@ -62,7 +60,7 @@ class MavenBuild {
|
||||||
|
|
||||||
private final File temp;
|
private final File temp;
|
||||||
|
|
||||||
private final Map<String, String> pomReplacements = new HashMap<>();
|
private final Map<String, String> pomReplacements;
|
||||||
|
|
||||||
private final List<String> goals = new ArrayList<>();
|
private final List<String> goals = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -74,24 +72,38 @@ class MavenBuild {
|
||||||
|
|
||||||
MavenBuild(File home) {
|
MavenBuild(File home) {
|
||||||
this.home = home;
|
this.home = home;
|
||||||
|
this.temp = createTempDirectory();
|
||||||
|
this.pomReplacements = getPomReplacements();
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createTempDirectory() {
|
||||||
try {
|
try {
|
||||||
this.temp = Files.createTempDirectory("maven-build").toFile().getCanonicalFile();
|
return Files.createTempDirectory("maven-build").toFile().getCanonicalFile();
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
this.pomReplacements.put("java.version", "1.8");
|
}
|
||||||
this.pomReplacements.put("project.groupId", "org.springframework.boot");
|
|
||||||
this.pomReplacements.put("project.artifactId", "spring-boot-maven-plugin");
|
private Map<String, String> getPomReplacements() {
|
||||||
this.pomReplacements.put("project.version", determineVersion());
|
Map<String, String> replacements = new HashMap<>();
|
||||||
this.pomReplacements.put("log4j2.version", "2.13.3");
|
SpringBootDependenciesBom bom = new SpringBootDependenciesBom();
|
||||||
this.pomReplacements.put("maven-jar-plugin.version", "3.2.0");
|
replacements.put("java.version", "1.8");
|
||||||
this.pomReplacements.put("maven-toolchains-plugin.version", "3.0.0");
|
replacements.put("project.groupId", "org.springframework.boot");
|
||||||
this.pomReplacements.put("maven-war-plugin.version", "3.2.3");
|
replacements.put("project.artifactId", "spring-boot-maven-plugin");
|
||||||
this.pomReplacements.put("build-helper-maven-plugin.version", "3.0.0");
|
replacements.put("project.version", bom.get("version"));
|
||||||
this.pomReplacements.put("spring-framework.version", "5.3.0");
|
putReplacement(replacements, bom, "log4j2.version");
|
||||||
this.pomReplacements.put("jakarta-servlet.version", "4.0.4");
|
putReplacement(replacements, bom, "maven-jar-plugin.version");
|
||||||
this.pomReplacements.put("kotlin.version", "1.4.10");
|
putReplacement(replacements, bom, "maven-war-plugin.version");
|
||||||
|
putReplacement(replacements, bom, "build-helper-maven-plugin.version");
|
||||||
|
putReplacement(replacements, bom, "spring-framework.version");
|
||||||
|
putReplacement(replacements, bom, "jakarta-servlet.version");
|
||||||
|
putReplacement(replacements, bom, "kotlin.version");
|
||||||
|
return Collections.unmodifiableMap(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putReplacement(Map<String, String> replacements, SpringBootDependenciesBom bom, String property) {
|
||||||
|
replacements.put(property, bom.get("properties/" + property));
|
||||||
}
|
}
|
||||||
|
|
||||||
MavenBuild project(String project) {
|
MavenBuild project(String project) {
|
||||||
|
|
@ -197,21 +209,6 @@ class MavenBuild {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineVersion() {
|
|
||||||
File gradleProperties = new File("gradle.properties").getAbsoluteFile();
|
|
||||||
while (!gradleProperties.isFile()) {
|
|
||||||
gradleProperties = new File(gradleProperties.getParentFile().getParentFile(), "gradle.properties");
|
|
||||||
}
|
|
||||||
Properties properties = new Properties();
|
|
||||||
try (Reader reader = new FileReader(gradleProperties)) {
|
|
||||||
properties.load(reader);
|
|
||||||
return properties.getProperty("version");
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to take on a maven project directory.
|
* Action to take on a maven project directory.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.maven;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPath;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to values in the spring-boot-dependencies effective BOM.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
class SpringBootDependenciesBom {
|
||||||
|
|
||||||
|
private static final String XML = "spring-boot-dependencies-effective-bom.xml";
|
||||||
|
|
||||||
|
private final Document document;
|
||||||
|
|
||||||
|
private final XPath xpath;
|
||||||
|
|
||||||
|
SpringBootDependenciesBom() {
|
||||||
|
this.document = loadDocument();
|
||||||
|
this.xpath = XPathFactory.newInstance().newXPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document loadDocument() {
|
||||||
|
try {
|
||||||
|
try (InputStream inputStream = getClass().getResourceAsStream(XML)) {
|
||||||
|
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||||
|
return builder.parse(inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ParserConfigurationException | SAXException | IOException ex) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String get(String expression) {
|
||||||
|
try {
|
||||||
|
Node node = (Node) this.xpath.compile("/project/" + expression).evaluate(this.document,
|
||||||
|
XPathConstants.NODE);
|
||||||
|
String text = (node != null) ? node.getTextContent() : null;
|
||||||
|
Assert.hasLength(text, () -> "No result for expression " + expression);
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
catch (XPathExpressionException ex) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-toolchains-plugin</artifactId>
|
<artifactId>maven-toolchains-plugin</artifactId>
|
||||||
<version>@maven-toolchains-plugin.version@</version>
|
<version>3.0.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue