mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-23 01:39:02 +00:00
Avoid using the deprecated Project.getProperties method
Gradle 9.6 deprecates Project.getProperties, which will be removed in Gradle 10. Use ProviderFactory.gradleProperty to read the required properties in AntoraAsciidocAttributes and the image system tests build script. Preserve null handling for missing Antora properties and fall back to the project version when springBootVersion is not configured. Update the provider mocks and add tests for the GraalVM plugin version attribute. Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com> See gh-51635
This commit is contained in:
committed by
Andy Wilkinson
parent
abbb298039
commit
6823d37408
+6
-4
@@ -26,6 +26,7 @@ import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.provider.ProviderFactory;
|
||||
|
||||
import org.springframework.boot.build.artifacts.ArtifactRelease;
|
||||
import org.springframework.boot.build.bom.BomExtension;
|
||||
@@ -59,7 +60,7 @@ public class AntoraAsciidocAttributes {
|
||||
|
||||
private final ResolvedBom resolvedBom;
|
||||
|
||||
private final Map<String, ?> projectProperties;
|
||||
private final ProviderFactory providers;
|
||||
|
||||
public AntoraAsciidocAttributes(Project project, BomExtension dependencyBom, ResolvedBom resolvedBom) {
|
||||
this.version = String.valueOf(project.getVersion());
|
||||
@@ -68,7 +69,7 @@ public class AntoraAsciidocAttributes {
|
||||
this.artifactRelease = ArtifactRelease.forProject(project);
|
||||
this.libraries = dependencyBom.getLibraries();
|
||||
this.resolvedBom = resolvedBom;
|
||||
this.projectProperties = project.getProperties();
|
||||
this.providers = project.getProviders();
|
||||
}
|
||||
|
||||
public Map<String, String> get() {
|
||||
@@ -108,8 +109,9 @@ public class AntoraAsciidocAttributes {
|
||||
|
||||
private void addVersionAttributes(Map<String, String> attributes, Map<String, String> internal) {
|
||||
this.libraries.forEach((library) -> addVersionAttributes(attributes, library));
|
||||
attributes.put("version-native-build-tools", (String) this.projectProperties.get("nativeBuildToolsVersion"));
|
||||
attributes.put("version-graal", (String) this.projectProperties.get("graalVersion"));
|
||||
attributes.put("version-native-build-tools",
|
||||
this.providers.gradleProperty("nativeBuildToolsVersion").getOrNull());
|
||||
attributes.put("version-graal", this.providers.gradleProperty("graalVersion").getOrNull());
|
||||
}
|
||||
|
||||
private void addVersionAttributes(Map<String, String> attributes, Library library) {
|
||||
|
||||
+22
-2
@@ -26,6 +26,8 @@ import java.util.function.Function;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.ExtensionContainer;
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.provider.ProviderFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.build.bom.BomExtension;
|
||||
@@ -115,6 +117,13 @@ class AntoraAsciidocAttributesTests {
|
||||
assertThat(attributes.get()).containsEntry("version-native-build-tools", "3.4.5");
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionGraal() {
|
||||
AntoraAsciidocAttributes attributes = attributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
|
||||
mockDependencyVersions(), Map.of("graalVersion", "25"));
|
||||
assertThat(attributes.get()).containsEntry("version-graal", "25");
|
||||
}
|
||||
|
||||
@Test
|
||||
void urlArtifactRepositoryWhenRelease() {
|
||||
AntoraAsciidocAttributes attributes = attributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
|
||||
@@ -234,7 +243,6 @@ class AntoraAsciidocAttributesTests {
|
||||
assertThat(keys.indexOf("include-java")).isLessThan(keys.indexOf("code-spring-boot-latest"));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private AntoraAsciidocAttributes attributes(String version, boolean latestVersion, BuildType buildType,
|
||||
List<Library> libraries, Map<String, String> dependencyVersions, Map<String, ?> projectProperties) {
|
||||
libraries = (libraries != null) ? libraries : Collections.emptyList();
|
||||
@@ -246,7 +254,8 @@ class AntoraAsciidocAttributesTests {
|
||||
given(project.findProperty("latestVersion")).willReturn(String.valueOf(latestVersion));
|
||||
given(project.findProperty("spring.build-type"))
|
||||
.willReturn((buildType == BuildType.OPEN_SOURCE) ? "oss" : "commercial");
|
||||
given(project.getProperties()).willReturn((Map) projectProperties);
|
||||
ProviderFactory providers = mockProviders(projectProperties);
|
||||
given(project.getProviders()).willReturn(providers);
|
||||
given(project.getExtensions()).willReturn(extensions);
|
||||
given(extensions.getExtraProperties()).willReturn(extraPropertiesExtension);
|
||||
BomExtension dependencyBom = mock();
|
||||
@@ -262,6 +271,17 @@ class AntoraAsciidocAttributesTests {
|
||||
return new AntoraAsciidocAttributes(project, dependencyBom, resolvedBom);
|
||||
}
|
||||
|
||||
private ProviderFactory mockProviders(Map<String, ?> projectProperties) {
|
||||
ProviderFactory providers = mock();
|
||||
given(providers.gradleProperty(any(String.class))).willAnswer((invocation) -> {
|
||||
String propertyName = invocation.getArgument(0);
|
||||
Provider<Object> provider = mock();
|
||||
given(provider.getOrNull()).willReturn(projectProperties.get(propertyName));
|
||||
return provider;
|
||||
});
|
||||
return providers;
|
||||
}
|
||||
|
||||
private Library mockLibrary(Map<LinkType, List<Link>> links) {
|
||||
return mockLibrary(new Links(links), Collections.emptyMap());
|
||||
}
|
||||
|
||||
@@ -35,11 +35,8 @@ tasks.register("syncMavenRepository", Sync) {
|
||||
|
||||
systemTest {
|
||||
dependsOn syncMavenRepository
|
||||
if (project.hasProperty("springBootVersion")) {
|
||||
systemProperty "springBootVersion", project.properties["springBootVersion"]
|
||||
} else {
|
||||
systemProperty "springBootVersion", project.getVersion()
|
||||
}
|
||||
systemProperty "springBootVersion",
|
||||
providers.gradleProperty("springBootVersion").getOrElse(project.getVersion().toString())
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
Reference in New Issue
Block a user