Supports for building Spring Boot applications as GraalVM native images.
https://plugins.gradle.org/plugin/com.github.ayltai.spring-graalvm-native-plugin
Using the plugins DSL:
plugins {
id 'com.github.ayltai.spring-graalvm-native-plugin' version '1.4.10'
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.com.github.ayltai:spring-graalvm-native-plugin:1.4.10'
}
}
apply plugin: 'com.github.ayltai.spring-graalvm-native-plugin'
Using the plugins DSL:
plugins {
id('com.github.ayltai.spring-graalvm-native-plugin') version '1.4.10'
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url = uri('https://plugins.gradle.org/m2/')
}
}
dependencies {
classpath('gradle.plugin.com.github.ayltai:spring-graalvm-native-plugin:1.4.10')
}
}
This plugin uses the following example Gradle extension for configuration:
nativeImage {
mainClassName = 'com.example.springboot.Application'
reportExceptionStackTraces = true
removeUnusedAutoConfig = true
removeYamlSupport = true
maxHeapSize = '6G'
}
More configuration options can be found here.
You need to specify proxyBeanMethods = false
for your @SpringBootApplication
annotation:
@SpringBootApplication(proxyBeanMethods = false)
public class TomcatApplication {
public static void main(final String[] args) {
SpringApplication.run(TomcatApplication.class, args);
}
}
- Run the Gradle task
buildNativeImage
- The native image can be located at
<buildDir>/native
samples contains various samples that demonstrate the basic usage of this Gradle plugin.
Property | Type | Description |
---|---|---|
toolVersion |
String |
The GraalVM Community Edition version to download. Default to 21.1.0 . |
javaVersion |
String |
The JDK version to be downloaded with GraalVM Community Edition. Default to 8 . |
download |
String |
Specify when to download GraalVM Community Edition. Supports default which downloads GraalVM tools only if they are not already downloaded, always which always (re-)download GraalVM tools, and skip which skips downloading GraalVM tools and assumes they are already installed. |
mainClassName (Required) |
String |
The fully qualified name of the Java class that contains a main method for the entry point of the Native Image executable. |
traceClassInitialization |
boolean |
(Deprecated. Use traceClassInitializationEnabled if you use GraalVM 20.2.0 or below, and traceClassInitializationFor if you use GraalVM 20.3.0 or above.) Provides useful information to debug class initialization issues. |
traceClassInitializationEnabled |
boolean |
(For GraalVM 20.2.0 or below) Provides useful information to debug class initialization issues. |
traceClassInitializationFor |
List<String> |
(For GraalVM 20.3.0 or above) A comma-separated list of fully qualified class names that class initialization is traced for. |
removeSaturatedTypeFlows |
boolean |
Reduces build time and decrease build memory consumption, especially for big projects. |
reportExceptionStackTraces |
boolean |
Provides more detail should something go wrong. |
printAnalysisCallTree |
boolean |
Helps to find what classes, methods, and fields are used and why. You can find more details in GraalVM reports documentation. |
disableToolchainChecking |
boolean |
Prevent native-toolchain checking. |
enableAllSecurityServices |
boolean |
Adds all security service classes to the generated image. Required for HTTPS and crypto. |
enableHttp |
boolean |
Enables HTTP support in the generated image. |
enableHttps |
boolean |
Enables HTTPS support in the generated image. |
enableUrlProtocols |
List<String> |
Specifies a list of URL protocols to be enabled in the generated image. |
staticallyLinked |
boolean |
Builds a statically linked executable, useful to deploy on a FROM scratch Docker image. |
warnMissingSelectorHints |
boolean |
Switches the feature from a hard error for missing hints to a warning. |
removeUnusedAutoConfig |
boolean |
Disables removal of unused configurations. |
verbose |
boolean |
Makes image building output more verbose. |
removeYamlSupport |
boolean |
Removes Yaml support from Spring Boot, enabling faster compilation and smaller executables. |
removeXmlSupport |
boolean |
Removes XML support from Spring Boot, enabling faster compilation and smaller executables. |
removeSpelSupport |
boolean |
Removes SpEL support from Spring Boot, enabling faster compilation and smaller executables. |
removeJmxSupport |
boolean |
Removes JMX support from Spring Boot, enabling faster compilation and smaller executables. |
verify |
boolean |
Switches on the verifier mode. |
springNativeVerbose |
boolean |
Outputs lots of information about the feature behavior as it processes auto-configuration and chooses which to include. |
springNativeMode |
String |
Switches how much configuration the feature actually provides to native-image. The default is reflection which provides resource, initialization, proxy, and reflection (using auto-configuration hints) configuration for native images as well as substitutions. agent should be used if only wishing the feature to provide substitutions and initialization configuration - in this mode you should have used the agent to collect the rest of the configuration. functional is when working with functional bean registration (Spring Fu style). In this mode the feature will provide initialization and resource configuration but nothing more. init should be used if only wishing to provide initialization configuration and substitutions. |
dumpConfig |
String |
Dumps the configuration to the specified file. |
maxHeapSize |
String |
Maximum allowed Java heap size for building GraalVM Native Image. |
initializeAtBuildTime |
List<String> |
Use it with specific classes or package to initialize classes at build time. |
extraArgs |
List<String> |
Add any native-image compiler arguments not covered by spring-graalvm-native-plugin . |
See Spring GraalVM Native configuration options for more details.
setup-graalvm is a GitHub action that sets up a GraalVM environment for your GitHub workflow.