All Projects → mike-neck → graalvm-native-image-plugin

mike-neck / graalvm-native-image-plugin

Licence: Apache-2.0 license
A Gradle plugin which creates a native executable via GraalVM's native-image. This is a thin wrapper of the native-image command.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects
shell
77523 projects
jq
24 projects

Projects that are alternatives of or similar to graalvm-native-image-plugin

native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (+86.67%)
Mutual labels:  gradle-plugin, graalvm, native-image
connor
A commandline tool for resetting Kafka Connect source connector offsets.
Stars: ✭ 17 (-81.11%)
Mutual labels:  graalvm, native-image
springboot-helloworld-native
Example helloWorld SpringBoot project which compiles to native code with GraalVM
Stars: ✭ 14 (-84.44%)
Mutual labels:  graalvm, native-image
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+3551.11%)
Mutual labels:  graalvm, native-image
holy-lambda
The extraordinary simple, performant, and extensible custom AWS Lambda runtime for Clojure.
Stars: ✭ 318 (+253.33%)
Mutual labels:  graalvm, native-image
Google-Authenticator
Clojure program to compute your google authenticator OTP using TOTP
Stars: ✭ 23 (-74.44%)
Mutual labels:  graalvm, native-image
GraalVMREPL
REPL (read–eval–print loop) shell built on top of JavaFX and GraalVM stack, incorporating GraalJS, GraalPython, TruffleRuby and FastR
Stars: ✭ 31 (-65.56%)
Mutual labels:  graalvm
qbicc
Experimental static compiler for Java programs.
Stars: ✭ 118 (+31.11%)
Mutual labels:  native-image
micronaut-camunda-external-client
This open source project allows you to easily integrate Camunda's External Task Clients into Micronaut projects: simply add a dependency in your Micronaut project
Stars: ✭ 19 (-78.89%)
Mutual labels:  graalvm
ghidraal
A Ghidra extension for scripting with GraalVM languages, including Javascript, Python3, R, and Ruby.
Stars: ✭ 48 (-46.67%)
Mutual labels:  graalvm
gradle-grammar-kit-plugin
Gradle plugin for generating lexers (with JFlex) and BNF parsers (with Grammar-Kit) for IntelliJ language plugins
Stars: ✭ 76 (-15.56%)
Mutual labels:  gradle-plugin
gradle-android-git
Gradle plugin for Android apps to manage Git dependency (gag)
Stars: ✭ 22 (-75.56%)
Mutual labels:  gradle-plugin
jacoco-gradle-testkit-plugin
Gradle plugin for JaCoCo code coverage in tests using Gradle TestKit
Stars: ✭ 37 (-58.89%)
Mutual labels:  gradle-plugin
grakkit
A modern JavaScript development environment for Minecraft.
Stars: ✭ 184 (+104.44%)
Mutual labels:  graalvm
gradle-flatbuffers-plugin
Gradle plugin for generating code from Google FlatBuffers schemas
Stars: ✭ 20 (-77.78%)
Mutual labels:  gradle-plugin
gradle-natives
Gradle plugin to aid in managing native libraries associated with Java-based projects.
Stars: ✭ 32 (-64.44%)
Mutual labels:  gradle-plugin
mozart-graal
An implementation of Oz on top of Truffle and Graal
Stars: ✭ 37 (-58.89%)
Mutual labels:  graalvm
blowdryer
Keep your gradle builds dry 干
Stars: ✭ 22 (-75.56%)
Mutual labels:  gradle-plugin
Android-So-Handler
支持APK包中所有System.Load/LoadLibrary加载的So库文件(Maven、aar文件引入三方库、源码引入的so文件),对So文件进行7z压缩与云端下发,完成apk瘦身
Stars: ✭ 64 (-28.89%)
Mutual labels:  gradle-plugin
badass-runtime-plugin
Create a custom runtime image of your non-modular application
Stars: ✭ 143 (+58.89%)
Mutual labels:  gradle-plugin

GraalVM Native Image Plugin

Run Gradle Tests Gradle Plugin Portal


This plugin offers a task (nativeImage), which wraps GraalVM's tool native-image installed in a machine.

Configuration

NativeImageTask

You can configure options via nativeImage {}.

  • graalVmHome - The Home directory of GraalVM, required.
  • jarTask - A task of JarTask whose output jar will be converted to native executable.(default: jar task)
  • mainClass - (Deprecated, configure via buildType { executable { main = ... } }) A name of main class, required.
  • executableName - A name of executable, required.
  • runtimeClasspath - A configuration of runtime classpath.(default: runtimeClasspath Configuration)
  • outputDirectory - An output directory under which the native image will be generated.(default: $buildDir/native-image)
  • buildType {} - A type of build, required. BuildTypeSelector will be passed to this closure.
    • buildTypeSelector.sharedLibrary - To build shared library, return this.
    • buildTypeSelector.executable {} - To build executable, call executable {} block, and configure its main with the application's main class name.

You can configure arguments to be passed to GraalVM via arguments(String...) method.

  • arguments(String...) - native-image command's arguments.
  • arguments(Provider<String>...) - native-image command's arguments with Provider<String> type.
  • arguments {} - Configure native-image command's arguments in configuration block.
    • add(String) - Equivalent to arguments(String...).
    • add(Provider<String>) - Equivalent to arguments(Provider<String>...).

For more information, please see appendix at the bottom of this README.

GenerateNativeImageConfigTask

You can configure running application parameters by generateNativeImageConfig {} block(GenerateNativeImageConfigTask).

  • enabled - A boolean property whether to run this task. This plugin disables generateNativeImageConfig task in default. Please set true to this property to run generateNativeImageConfig task.
  • mainClass - The main class name for running application.
  • byRunningApplication {} - Configuration block to run your application. You can configure multiple times.
    • stdIn(String) - standard input for your application.
    • arguments(String...) - Command line arguments, which will be given to your application.
    • environment(Map<String, String>) - Environmental variable for your application.
  • byRunningApplicationWithoutArguments() - Run application without any configuration.

Example

1. Example script of building executable.

Gradle Groovy DSL

plugins {
  id 'java'
  id 'org.mikeneck.graalvm-native-image' version 'v1.4.0'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.slf4j:slf4j-simple:1.7.28'
}

import org.mikeneck.graalvm.BuildTypeSelector

nativeImage {
  graalVmHome = System.getProperty('java.home')
  mainClass = 'com.example.App' // Deprecated, use buildType.executable.main as follows instead.
  buildType { BuildTypeSelector build ->
    build.executable {
      main = 'com.example.App'
    }
  }
  executableName = 'my-native-application'
  outputDirectory = file("$buildDir/bin")
  arguments {
    add '--no-fallback'
    add '--enable-all-security-services'
    add options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer')
    add '--initialize-at-run-time=com.example.runtime'
    add '--report-unsupported-elements-at-runtime'
  }
}

generateNativeImageConfig {
  enabled = true
  byRunningApplication {
    stdIn("""
    |total: 2
    |contents:
    |  - name: foo
    |    size: 2052
    |""".stripMargin())
  }
  byRunningApplicationWithoutArguments()
  byRunningApplication {
    arguments('-h')
  }
}

Gradle Kotlin DSL

import org.mikeneck.graalvm.GenerateNativeImageConfigTask

plugins {
  kotlin("jvm") version "1.3.72"
  id("org.mikeneck.graalvm-native-image") version "v1.4.0"
}

repositories {
  mavenCentral()
}

dependencies {
  implementation("org.slf4j:slf4j-simple:1.7.28")
}

nativeImage {
    graalVmHome = System.getenv("JAVA_HOME")
    mainClass ="com.example.App" // Deprecated, use `buildType.executable.main` as follows instead.
    buildType { build ->
      build.executable(main = 'com.example.App')
    }
    executableName = "my-native-application"
    outputDirectory = file("$buildDir/executable")
    arguments(
        "--no-fallback",
        "--enable-all-security-services",
        options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer'),
        "--initialize-at-run-time=com.example.runtime",
        "--report-unsupported-elements-at-runtime"
    )
}

generateNativeImageConfig {
  enabled = true
  byRunningApplication {
    stdIn("""
      |total: 2
      |contents:
      |  - name: foo
      |    size: 2052
      |""".trimMargin())
  }
  byRunningApplicationWithoutArguments()
  byRunningApplication {
    arguments('-h')
  }
}

2. Example script of building shared library.

Shared library feature is one of GraalVM's feature to build shared library('so' file in linux, 'dylib' file in OS X), only available Java11 or later.

Gradle Groovy DSL

plugins {
  id 'java'
  id 'org.mikeneck.graalvm-native-image' version 'v1.4.0'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.slf4j:slf4j-simple:1.7.28'
}

import org.mikeneck.graalvm.BuildTypeSelector

nativeImage {
  graalVmHome = System.getProperty('java.home')
  buildType { BuildTypeSelector build ->
    build.sharedLibrary
  }
  executableName = 'my-native-lib'
  outputDirectory = file("$buildDir/native-lib")
  arguments {
    add '--no-fallback'
    add '--enable-all-security-services'
    add options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer')
    add '--initialize-at-run-time=com.example.runtime'
    add '--report-unsupported-elements-at-runtime'
  }
}

generateNativeImageConfig {
  enabled = true
  // If config file generation is required, set main class name here in generateNativeImageConfig block.
  mainClass = 'com.example.RunMainForGenerateConfigJson'
  byRunningApplication {
    stdIn("""
    |total: 2
    |contents:
    |  - name: foo
    |    size: 2052
    |""".stripMargin())
  }
  byRunningApplicationWithoutArguments()
  byRunningApplication {
    arguments('-h')
  }
}

Gradle Kotlin DSL

import org.mikeneck.graalvm.GenerateNativeImageConfigTask

plugins {
  kotlin("jvm") version "1.3.72"
  id("org.mikeneck.graalvm-native-image") version "v1.4.0"
}

repositories {
  mavenCentral()
}

dependencies {
  implementation("org.slf4j:slf4j-simple:1.7.28")
}

nativeImage {
    graalVmHome = System.getenv("JAVA_HOME")
    buildType { sharedLibrary }
    executableName = "my-native-lib"
    outputDirectory = file("$buildDir/native-lib")
    arguments(
        "--no-fallback",
        "--enable-all-security-services",
        options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer'),
        "--initialize-at-run-time=com.example.runtime",
        "--report-unsupported-elements-at-runtime"
    )
}

generateNativeImageConfig {
  enabled = true
  // If config file generation is required, set main class name here in generateNativeImageConfig block.
  mainClass = "com.example.RunMainForGenerateConfigJson"
  byRunningApplication {
    stdIn("""
      |total: 2
      |contents:
      |  - name: foo
      |    size: 2052
      |""".trimMargin())
  }
  byRunningApplicationWithoutArguments()
  byRunningApplication {
    arguments('-h')
  }
}

run task

For linux/mac users

(Optional)Before running nativeImage task, GraalVM and native-image command should be installed. Version v0.5.0 or later, the plugin has installNativeImage task which execute installation command(gu install native-image) so that users do not need to run gu command.

# Prerequisites: GraalVM is installed to your machine.
# Then install native-image.
$ gu install native-image

# Run nativeImage task.
$ ./gradlew nativeImage

# An executable will be created at native-image directory under the project's build directory
$ ls build/native-image
my-native-application
For Windows users

Make sure you are running nativeImage task on Windows SDK 7.1 Command Prompt.

For GitHub Actions

If you are planning releasing both MacOS X and Linux applications, please refer example workflow under example directory.

generateNativeImageConfig task

This task requires native-image command. If your machine has no native-image command, run gu command or installNativeImage task before running generateNativeImageConfig task.


nativeImage task configuration appendix

TraceClassInitialization option

As of GraalVM 20.3.0, the way to pass TraceClassInitialization option is changed. So we offer a convenient way to create TraceClassInitialization option. In this way you can create the option via an options object available from nativeImageTask.

nativeImage {
  arguments {
    // When used with GraalVM 20.3.0 or later
    // -H:TraceClassInitialization=com.example.WantTracingInInitializationClass,com.example.Another
    // When used with GraalVM 20.2.0 or earlier
    // -H:+TraceClassInitialization
    add options.traceClassInitialization { 'com.example.WantTracingInInitializationClass,com.example.Another' }
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].