From 3703b317cebf7d0002ceb0a9b6b06d7d9179b35d Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 12 Jul 2022 13:41:12 +0200 Subject: [PATCH] Enable GraalVM reachability metadata repository Closes gh-31687 --- .../spring-boot-starter-parent/build.gradle | 5 +++++ .../boot/gradle/plugin/NativeImagePluginAction.java | 9 +++++++++ .../boot/testsupport/gradle/testkit/GradleBuild.java | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle index ab4660d2b4..f451825fdb 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle @@ -249,6 +249,11 @@ publishing.publications.withType(MavenPublication) { plugin { delegate.groupId('org.graalvm.buildtools') delegate.artifactId('native-maven-plugin') + configuration { + metadataRepository { + delegate.enabled('true') + } + } executions { execution { delegate.id('build-native') diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/NativeImagePluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/NativeImagePluginAction.java index 3cfbc324f0..253c45a0c2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/NativeImagePluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/NativeImagePluginAction.java @@ -18,10 +18,12 @@ package org.springframework.boot.gradle.plugin; import org.graalvm.buildtools.gradle.NativeImagePlugin; import org.graalvm.buildtools.gradle.dsl.GraalVMExtension; +import org.graalvm.buildtools.gradle.dsl.GraalVMReachabilityMetadataRepositoryExtension; import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask; import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.plugins.ExtensionAware; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; @@ -53,6 +55,13 @@ class NativeImagePluginAction implements PluginApplicationAction { }); GraalVMExtension graalVmExtension = project.getExtensions().getByType(GraalVMExtension.class); graalVmExtension.getToolchainDetection().set(false); + reachabilityExtensionOn(graalVmExtension).getEnabled().set(true); + } + + private static GraalVMReachabilityMetadataRepositoryExtension reachabilityExtensionOn( + GraalVMExtension graalVmExtension) { + return ((ExtensionAware) graalVmExtension).getExtensions() + .getByType(GraalVMReachabilityMetadataRepositoryExtension.class); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java index 768a5ebc32..72bcd1483f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java @@ -126,7 +126,8 @@ public class GradleBuild { new File(pathOfJarContaining(JsonView.class)), new File(pathOfJarContaining(Platform.class)), new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)), new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")), - new File(pathOfJarContaining("org.graalvm.reachability.JvmReachabilityMetadataRepository"))); + new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")), + new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants"))); } private String pathOfJarContaining(String className) {