Fail more elegantly when GraalVM version is too old

Closes gh-32924
This commit is contained in:
Andy Wilkinson 2022-11-04 13:05:22 +00:00
parent 19b2bd6d1c
commit fe8644cc59
5 changed files with 45 additions and 0 deletions

View File

@ -261,6 +261,7 @@ publishing.publications.withType(MavenPublication) {
metadataRepository { metadataRepository {
delegate.enabled('true') delegate.enabled('true')
} }
delegate.requiredVersion('22.3')
} }
executions { executions {
execution { execution {
@ -305,6 +306,7 @@ publishing.publications.withType(MavenPublication) {
metadataRepository { metadataRepository {
delegate.enabled('true') delegate.enabled('true')
} }
delegate.requiredVersion('22.3')
} }
executions { executions {
execution { execution {

View File

@ -78,6 +78,7 @@ When the {nbt-gradle-plugin}[GraalVM Native Image plugin] is applied to a projec
. Adds the output of the `aot` source set to the classpath of the `main` GraalVM native binary. . Adds the output of the `aot` source set to the classpath of the `main` GraalVM native binary.
. Adds the output of the `aotTest` source set to the classpath of the `test` GraalVM native binary. . Adds the output of the `aotTest` source set to the classpath of the `test` GraalVM native binary.
. Configures the GraalVM extension to disable Toolchain detection. . Configures the GraalVM extension to disable Toolchain detection.
. Configures each GraalVM native binary to require GraalVM 22.3 or later.
. Configures the `bootJar` task to include the reachability metadata produced by the `collectReachabilityMetadata` task in its jar. . Configures the `bootJar` task to include the reachability metadata produced by the `collectReachabilityMetadata` task in its jar.
. Configures the `bootBuildImage` task to use `paketobuildpacks/builder:tiny` as its builder and to set `BP_NATIVE_IMAGE` to `true` in its environment. . Configures the `bootBuildImage` task to use `paketobuildpacks/builder:tiny` as its builder and to set `BP_NATIVE_IMAGE` to `true` in its environment.

View File

@ -24,6 +24,7 @@ import org.graalvm.buildtools.gradle.NativeImagePlugin;
import org.graalvm.buildtools.gradle.dsl.GraalVMExtension; import org.graalvm.buildtools.gradle.dsl.GraalVMExtension;
import org.graalvm.buildtools.gradle.dsl.GraalVMReachabilityMetadataRepositoryExtension; import org.graalvm.buildtools.gradle.dsl.GraalVMReachabilityMetadataRepositoryExtension;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
@ -94,6 +95,15 @@ class NativeImagePluginAction implements PluginApplicationAction {
private GraalVMExtension configureGraalVmExtension(Project project) { private GraalVMExtension configureGraalVmExtension(Project project) {
GraalVMExtension extension = project.getExtensions().getByType(GraalVMExtension.class); GraalVMExtension extension = project.getExtensions().getByType(GraalVMExtension.class);
extension.getToolchainDetection().set(false); extension.getToolchainDetection().set(false);
extension.getBinaries().configureEach((options) -> {
try {
options.getRequiredVersion().convention("22.3");
}
catch (NoSuchMethodError ex) {
throw new GradleException("Incompatible version of org.graalvm.buildtools.native plugin. "
+ "Please upgrade to 0.9.17 or later.");
}
});
return extension; return extension;
} }

View File

@ -115,6 +115,12 @@ class NativeImagePluginActionIntegrationTests {
projectPath("build/resources/aotTest"), projectPath("build/generated/aotTestClasses")); projectPath("build/resources/aotTest"), projectPath("build/generated/aotTestClasses"));
} }
@TestTemplate
void nativeImageBinariesRequireGraal22Dot3() {
BuildResult result = this.gradleBuild.build("requiredGraalVersion");
assertThat(result.getOutput()).contains("custom: 22.3", "main: 22.3", "test: 22.3");
}
private String projectPath(String path) { private String projectPath(String path) {
return new File(this.gradleBuild.getProjectDir(), path).getAbsolutePath(); return new File(this.gradleBuild.getProjectDir(), path).getAbsolutePath();
} }

View File

@ -0,0 +1,26 @@
plugins {
id 'org.springframework.boot' version '{version}'
id 'java'
}
apply plugin: 'org.graalvm.buildtools.native'
repositories {
mavenCentral()
}
graalvmNative {
binaries {
custom {
}
}
}
task('requiredGraalVersion') {
doFirst {
println "Binaries ${graalvmNative.binaries.asMap}"
graalvmNative.binaries.asMap.each { name, binary ->
println "${name}: ${binary.requiredVersion.get()}"
}
}
}