Remove spring-boot.version property from spring-boot-dependencies

The version of Spring Boot should not be modifiable by a property,
only being using a different version of spring-boot-dependencies or
spring-boot-starter-parent.

Fixes gh-23174
pull/23585/head
Andy Wilkinson 4 years ago
parent d5234a9254
commit 358b9f839a

@ -169,15 +169,18 @@ public class BomExtension {
private void addLibrary(Library library) {
this.libraries.add(library);
this.properties.put(library.getVersionProperty(), library.getVersion());
String versionProperty = library.getVersionProperty();
if (versionProperty != null) {
this.properties.put(versionProperty, library.getVersion());
}
for (Group group : library.getGroups()) {
for (Module module : group.getModules()) {
putArtifactVersionProperty(group.getId(), module.getName(), library.getVersionProperty());
putArtifactVersionProperty(group.getId(), module.getName(), versionProperty);
this.dependencyHandler.getConstraints().add(JavaPlatformPlugin.API_CONFIGURATION_NAME,
createDependencyNotation(group.getId(), module.getName(), library.getVersion()));
}
for (String bomImport : group.getBoms()) {
putArtifactVersionProperty(group.getId(), bomImport, library.getVersionProperty());
putArtifactVersionProperty(group.getId(), bomImport, versionProperty);
String bomDependency = createDependencyNotation(group.getId(), bomImport, library.getVersion());
this.dependencyHandler.add(JavaPlatformPlugin.API_CONFIGURATION_NAME,
this.dependencyHandler.platform(bomDependency));

@ -168,7 +168,10 @@ public class BomPlugin implements Plugin<Project> {
Node plugin = new Node(plugins, "plugin");
plugin.appendNode("groupId", group.getId());
plugin.appendNode("artifactId", pluginName);
plugin.appendNode("version", "${" + library.getVersionProperty() + "}");
String versionProperty = library.getVersionProperty();
String value = (versionProperty != null) ? "${" + versionProperty + "}"
: library.getVersion().toString();
plugin.appendNode("version", value);
}
}
}

@ -55,7 +55,8 @@ public class Library {
this.name = name;
this.version = version;
this.groups = groups;
this.versionProperty = name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version";
this.versionProperty = "Spring Boot".equals(name) ? null
: name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version";
this.prohibitedVersions = prohibitedVersions;
}

@ -103,7 +103,10 @@ public class ExtractVersionConstraints extends DefaultTask {
Object bom = getProject().project(projectPath).getExtensions().getByName("bom");
BomExtension bomExtension = (BomExtension) bom;
for (Library lib : bomExtension.getLibraries()) {
this.versionProperties.add(new VersionProperty(lib.getName(), lib.getVersionProperty()));
String versionProperty = lib.getVersionProperty();
if (versionProperty != null) {
this.versionProperties.add(new VersionProperty(lib.getName(), versionProperty));
}
}
}

@ -16,11 +16,9 @@
package org.springframework.boot.build.bom;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.function.Consumer;
import org.gradle.testkit.runner.BuildResult;
@ -31,7 +29,6 @@ import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.build.DeployedPlugin;
import org.springframework.boot.build.assertj.NodeAssert;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -172,6 +169,33 @@ public class BomPluginIntegrationTests {
});
}
@Test
void libraryNamedSpringBootHasNoVersionProperty() throws IOException {
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
out.println("plugins {");
out.println(" id 'org.springframework.boot.bom'");
out.println("}");
out.println("bom {");
out.println(" library('Spring Boot', '1.2.3') {");
out.println(" group('org.springframework.boot') {");
out.println(" modules = [");
out.println(" 'spring-boot'");
out.println(" ]");
out.println(" }");
out.println(" }");
out.println("}");
}
generatePom((pom) -> {
assertThat(pom).textAtPath("//properties/spring-boot.version").isEmpty();
NodeAssert dependency = pom.nodeAtPath("//dependencyManagement/dependencies/dependency[1]");
assertThat(dependency).textAtPath("groupId").isEqualTo("org.springframework.boot");
assertThat(dependency).textAtPath("artifactId").isEqualTo("spring-boot");
assertThat(dependency).textAtPath("version").isEqualTo("1.2.3");
assertThat(dependency).textAtPath("scope").isNullOrEmpty();
assertThat(dependency).textAtPath("type").isNullOrEmpty();
});
}
private BuildResult runGradle(String... args) {
return GradleRunner.create().withDebug(true).withProjectDir(this.projectDir).withArguments(args)
.withPluginClasspath().build();
@ -180,12 +204,6 @@ public class BomPluginIntegrationTests {
private void generatePom(Consumer<NodeAssert> consumer) {
runGradle(DeployedPlugin.GENERATE_POM_TASK_NAME, "-s");
File generatedPomXml = new File(this.projectDir, "build/publications/maven/pom-default.xml");
try (Reader reader = new FileReader(generatedPomXml)) {
System.out.println(FileCopyUtils.copyToString(reader));
}
catch (IOException ex) {
}
assertThat(generatedPomXml).isFile();
consumer.accept(new NodeAssert(generatedPomXml));
}

Loading…
Cancel
Save