Giter Club home page Giter Club logo

spring-graalvm-native-plugin's Introduction

Spring GraalVM native Gradle plugin

GitHub workflow status Codacy grade Sonar quality gate Sonar violations (short format) Sonar Test Success Rate Code Coverage Sonar Coverage Maintainability Rating Reliability Rating Sonar Tech Debt Vulnerabilities Maintenance Release License

Supports for building Spring Boot applications as GraalVM native images.

https://plugins.gradle.org/plugin/com.github.ayltai.spring-graalvm-native-plugin

Buy me a coffee

Quick start

Apply Gradle plugin

Groovy

Using the plugins DSL:

plugins {
    id 'com.github.ayltai.spring-graalvm-native-plugin' version '1.4.7'
}

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.7'
    }
}

apply plugin: 'com.github.ayltai.spring-graalvm-native-plugin'

Kotlin

Using the plugins DSL:

plugins {
    id('com.github.ayltai.spring-graalvm-native-plugin') version '1.4.7'
}

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.7')
    }
}

Specify build arguments

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.

Update Spring Boot annotation

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);
    }
}

Build GraalVM Native Image

  1. Run the Gradle task buildNativeImage
  2. The native image can be located at <buildDir>/native

Sample project

samples contains various samples that demonstrate the basic usage of this Gradle plugin.

Configuration

Property Type Description
toolVersion String The GraalVM Community Edition version to download. Default to 21.0.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.

See Spring GraalVM Native configuration options for more details.

GitHub action

setup-graalvm is a GitHub action that sets up a GraalVM environment for your GitHub workflow.

License

MIT

References

spring-graalvm-native-plugin's People

Contributors

ayltai avatar celcius112 avatar dependabot-preview[bot] avatar huijiewei avatar mmoayyed avatar twpdesigner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.