{"id":13471915,"url":"https://github.com/mike-neck/graalvm-native-image-plugin","last_synced_at":"2026-01-12T11:41:50.168Z","repository":{"id":35982343,"uuid":"220639723","full_name":"mike-neck/graalvm-native-image-plugin","owner":"mike-neck","description":"A Gradle plugin which creates a native executable via GraalVM's native-image. This is a thin wrapper of the native-image command.","archived":false,"fork":false,"pushed_at":"2021-12-22T09:38:23.000Z","size":675,"stargazers_count":89,"open_issues_count":43,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T04:11:42.696Z","etag":null,"topics":["graalvm","gradle-plugin","native-image"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mike-neck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-09T12:34:58.000Z","updated_at":"2024-08-21T23:20:22.000Z","dependencies_parsed_at":"2022-07-15T20:00:47.104Z","dependency_job_id":null,"html_url":"https://github.com/mike-neck/graalvm-native-image-plugin","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-neck%2Fgraalvm-native-image-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-neck%2Fgraalvm-native-image-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-neck%2Fgraalvm-native-image-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mike-neck%2Fgraalvm-native-image-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mike-neck","download_url":"https://codeload.github.com/mike-neck/graalvm-native-image-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245681193,"owners_count":20655149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graalvm","gradle-plugin","native-image"],"created_at":"2024-07-31T16:00:50.331Z","updated_at":"2026-01-12T11:41:50.163Z","avatar_url":"https://github.com/mike-neck.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"GraalVM Native Image Plugin\n\n![Run Gradle Tests](https://github.com/mike-neck/graalvm-native-image-plugin/workflows/Run%20Gradle%20Tests/badge.svg?branch=master\u0026event=push)\n[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/org/mikeneck/graalvm-native-image/org.mikeneck.graalvm-native-image.gradle.plugin/maven-metadata.xml.svg?colorB=358504\u0026label=gradlePluginPortal)](https://plugins.gradle.org/plugin/org.mikeneck.graalvm-native-image)\n\n---\n\nThis plugin offers a task (`nativeImage`), which wraps GraalVM's tool `native-image` installed in a machine.\n\nConfiguration\n---\n\n### NativeImageTask\n\nYou can configure options via `nativeImage {}`.\n\n* `graalVmHome` - The Home directory of GraalVM, required.\n* `jarTask` - A task of `JarTask` whose output jar will be converted to native executable.(default: `jar` task)\n* `mainClass` - (Deprecated, configure via `buildType { executable { main = ... } }`) A name of main class, required.\n* `executableName` - A name of executable, required.\n* `runtimeClasspath` - A configuration of runtime classpath.(default: `runtimeClasspath` Configuration)\n* `outputDirectory` - An output directory under which the native image will be generated.(default: `$buildDir/native-image`)\n* `buildType {}` - A type of build, required. `BuildTypeSelector` will be passed to this closure.\n    - `buildTypeSelector.sharedLibrary` - To build shared library, return this.\n    - `buildTypeSelector.executable {}` - To build executable, call `executable {}` block, and configure its `main` with the application's main class name.\n\nYou can configure arguments to be passed to GraalVM via `arguments(String...)` method.\n\n- `arguments(String...)` - `native-image` command's arguments.\n- `arguments(Provider\u003cString\u003e...)` - `native-image` command's arguments with `Provider\u003cString\u003e` type.\n- `arguments {}` - Configure `native-image` command's arguments in configuration block.\n  - `add(String)` - Equivalent to `arguments(String...)`.\n  - `add(Provider\u003cString\u003e)` - Equivalent to `arguments(Provider\u003cString\u003e...)`.\n\nFor more information, please see appendix at the bottom of this README.\n\n### GenerateNativeImageConfigTask\n\nYou can configure running application parameters by `generateNativeImageConfig {}` block(`GenerateNativeImageConfigTask`).\n\n- `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.\n- `mainClass` - The main class name for running application.\n- `byRunningApplication {}` - Configuration block to run your application. You can configure multiple times.\n    - `stdIn(String)` - standard input for your application.\n    - `arguments(String...)` - Command line arguments, which will be given to your application.\n    - `environment(Map\u003cString, String\u003e)` - Environmental variable for your application.\n- `byRunningApplicationWithoutArguments()` - Run application without any configuration.\n\nExample\n---\n\n### 1. Example script of building executable.\n#### Gradle Groovy DSL\n```groovy\nplugins {\n  id 'java'\n  id 'org.mikeneck.graalvm-native-image' version 'v1.4.0'\n}\n\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  implementation 'org.slf4j:slf4j-simple:1.7.28'\n}\n\nimport org.mikeneck.graalvm.BuildTypeSelector\n\nnativeImage {\n  graalVmHome = System.getProperty('java.home')\n  mainClass = 'com.example.App' // Deprecated, use buildType.executable.main as follows instead.\n  buildType { BuildTypeSelector build -\u003e\n    build.executable {\n      main = 'com.example.App'\n    }\n  }\n  executableName = 'my-native-application'\n  outputDirectory = file(\"$buildDir/bin\")\n  arguments {\n    add '--no-fallback'\n    add '--enable-all-security-services'\n    add options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer')\n    add '--initialize-at-run-time=com.example.runtime'\n    add '--report-unsupported-elements-at-runtime'\n  }\n}\n\ngenerateNativeImageConfig {\n  enabled = true\n  byRunningApplication {\n    stdIn(\"\"\"\n    |total: 2\n    |contents:\n    |  - name: foo\n    |    size: 2052\n    |\"\"\".stripMargin())\n  }\n  byRunningApplicationWithoutArguments()\n  byRunningApplication {\n    arguments('-h')\n  }\n}\n```\n\n#### Gradle Kotlin DSL\n```kotlin\nimport org.mikeneck.graalvm.GenerateNativeImageConfigTask\n\nplugins {\n  kotlin(\"jvm\") version \"1.3.72\"\n  id(\"org.mikeneck.graalvm-native-image\") version \"v1.4.0\"\n}\n\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  implementation(\"org.slf4j:slf4j-simple:1.7.28\")\n}\n\nnativeImage {\n    graalVmHome = System.getenv(\"JAVA_HOME\")\n    mainClass =\"com.example.App\" // Deprecated, use `buildType.executable.main` as follows instead.\n    buildType { build -\u003e\n      build.executable(main = 'com.example.App')\n    }\n    executableName = \"my-native-application\"\n    outputDirectory = file(\"$buildDir/executable\")\n    arguments(\n        \"--no-fallback\",\n        \"--enable-all-security-services\",\n        options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer'),\n        \"--initialize-at-run-time=com.example.runtime\",\n        \"--report-unsupported-elements-at-runtime\"\n    )\n}\n\ngenerateNativeImageConfig {\n  enabled = true\n  byRunningApplication {\n    stdIn(\"\"\"\n      |total: 2\n      |contents:\n      |  - name: foo\n      |    size: 2052\n      |\"\"\".trimMargin())\n  }\n  byRunningApplicationWithoutArguments()\n  byRunningApplication {\n    arguments('-h')\n  }\n}\n```\n\n### 2. Example script of building shared library.\n\nShared 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.\n\n#### Gradle Groovy DSL\n```groovy\nplugins {\n  id 'java'\n  id 'org.mikeneck.graalvm-native-image' version 'v1.4.0'\n}\n\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  implementation 'org.slf4j:slf4j-simple:1.7.28'\n}\n\nimport org.mikeneck.graalvm.BuildTypeSelector\n\nnativeImage {\n  graalVmHome = System.getProperty('java.home')\n  buildType { BuildTypeSelector build -\u003e\n    build.sharedLibrary\n  }\n  executableName = 'my-native-lib'\n  outputDirectory = file(\"$buildDir/native-lib\")\n  arguments {\n    add '--no-fallback'\n    add '--enable-all-security-services'\n    add options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer')\n    add '--initialize-at-run-time=com.example.runtime'\n    add '--report-unsupported-elements-at-runtime'\n  }\n}\n\ngenerateNativeImageConfig {\n  enabled = true\n  // If config file generation is required, set main class name here in generateNativeImageConfig block.\n  mainClass = 'com.example.RunMainForGenerateConfigJson'\n  byRunningApplication {\n    stdIn(\"\"\"\n    |total: 2\n    |contents:\n    |  - name: foo\n    |    size: 2052\n    |\"\"\".stripMargin())\n  }\n  byRunningApplicationWithoutArguments()\n  byRunningApplication {\n    arguments('-h')\n  }\n}\n```\n\n#### Gradle Kotlin DSL\n```kotlin\nimport org.mikeneck.graalvm.GenerateNativeImageConfigTask\n\nplugins {\n  kotlin(\"jvm\") version \"1.3.72\"\n  id(\"org.mikeneck.graalvm-native-image\") version \"v1.4.0\"\n}\n\nrepositories {\n  mavenCentral()\n}\n\ndependencies {\n  implementation(\"org.slf4j:slf4j-simple:1.7.28\")\n}\n\nnativeImage {\n    graalVmHome = System.getenv(\"JAVA_HOME\")\n    buildType { sharedLibrary }\n    executableName = \"my-native-lib\"\n    outputDirectory = file(\"$buildDir/native-lib\")\n    arguments(\n        \"--no-fallback\",\n        \"--enable-all-security-services\",\n        options.traceClassInitialization('com.example.MyDataProvider,com.example.MyDataConsumer'),\n        \"--initialize-at-run-time=com.example.runtime\",\n        \"--report-unsupported-elements-at-runtime\"\n    )\n}\n\ngenerateNativeImageConfig {\n  enabled = true\n  // If config file generation is required, set main class name here in generateNativeImageConfig block.\n  mainClass = \"com.example.RunMainForGenerateConfigJson\"\n  byRunningApplication {\n    stdIn(\"\"\"\n      |total: 2\n      |contents:\n      |  - name: foo\n      |    size: 2052\n      |\"\"\".trimMargin())\n  }\n  byRunningApplicationWithoutArguments()\n  byRunningApplication {\n    arguments('-h')\n  }\n}\n```\n\n### run task\n\n##### For linux/mac users\n\n(Optional)Before running `nativeImage` task, GraalVM and `native-image` command should be installed.\nVersion v0.5.0 or later, the plugin has `installNativeImage` task which execute installation command(`gu install native-image`)\nso that users do not need to run `gu` command.\n\n```shell-session\n# Prerequisites: GraalVM is installed to your machine.\n# Then install native-image.\n$ gu install native-image\n\n# Run nativeImage task.\n$ ./gradlew nativeImage\n\n# An executable will be created at native-image directory under the project's build directory\n$ ls build/native-image\nmy-native-application\n```\n\n##### For Windows users\n\nMake sure you are running `nativeImage` task on Windows SDK 7.1 Command Prompt.\n\n##### For GitHub Actions\n\nIf you are planning releasing both MacOS X and Linux applications, please refer example workflow under `example` directory.\n\n### generateNativeImageConfig task\n\nThis task requires `native-image` command. If your machine has no `native-image` command,\nrun `gu` command or `installNativeImage` task before running `generateNativeImageConfig` task.\n\n---\n\n`nativeImage` task configuration appendix\n---\n\n### `TraceClassInitialization` option\n\nAs of GraalVM 20.3.0, the way to pass `TraceClassInitialization` option is changed.\nSo we offer a convenient way to create `TraceClassInitialization` option.\nIn this way you can create the option via an `options` object available from `nativeImageTask`.\n\n```groovy\nnativeImage {\n  arguments {\n    // When used with GraalVM 20.3.0 or later\n    // -H:TraceClassInitialization=com.example.WantTracingInInitializationClass,com.example.Another\n    // When used with GraalVM 20.2.0 or earlier\n    // -H:+TraceClassInitialization\n    add options.traceClassInitialization { 'com.example.WantTracingInInitializationClass,com.example.Another' }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmike-neck%2Fgraalvm-native-image-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmike-neck%2Fgraalvm-native-image-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmike-neck%2Fgraalvm-native-image-plugin/lists"}