Merge branch '4.1.x'

Closes gh-51648
This commit is contained in:
Andy Wilkinson
2026-09-09 11:00:51 +01:00
3 changed files with 38 additions and 12 deletions
@@ -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,10 +109,11 @@ 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());
attributes.put("version-protobuf-gradle-plugin",
(String) this.projectProperties.get("protobufGradlePluginVersion"));
this.providers.gradleProperty("protobufGradlePluginVersion").getOrNull());
}
private void addVersionAttributes(Map<String, String> attributes, Library library) {
@@ -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,20 @@ 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 versionProtobufGradlePlugin() {
AntoraAsciidocAttributes attributes = attributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), Map.of("protobufGradlePluginVersion", "3.4.5"));
assertThat(attributes.get()).containsEntry("version-protobuf-gradle-plugin", "3.4.5");
}
@Test
void urlArtifactRepositoryWhenRelease() {
AntoraAsciidocAttributes attributes = attributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
@@ -234,7 +250,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 +261,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 +278,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 {