Skip to content

Commit

Permalink
Review Maven/Gradle Build Tools NI guides
Browse files Browse the repository at this point in the history
  • Loading branch information
olyagpl committed Nov 29, 2022
1 parent 95ba29e commit a3bf346
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ permalink: /reference-manual/native-image/guides/use-native-image-gradle-plugin/
# Use Gradle to Build a Native Executable from a Java Application

You can use the Gradle plugin for GraalVM Native Image to build a native executable from a Java application in one step, in addition to a runnable JAR.
The plugin is provided as part of the [Native Build Tools project](https://graalvm.github.io/native-build-tools/latest/index.html) and uses the [Gradle build tool](https://gradle.org/).
The plugin is provided as part of the [Native Build Tools project](https://graalvm.github.io/native-build-tools/latest/index.html).

The Gradle plugin for GraalVM Native Image works with the `application` plugin and registers a number of tasks and extensions for you. For more information, see the [plugin documentation](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html).
The Gradle plugin for GraalVM Native Image works with the `application` plugin and registers a number of tasks and extensions for you.
For more information, see the [plugin documentation](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html).

This guide shows you how to use the Native Image Gradle plugin to build a native executable from a Java application, add support for dynamic features, and run JUnit tests.

Expand All @@ -26,7 +27,7 @@ We recommend that you follow the instructions and create the application step-by
git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-demo/fortune-gradle
```

> You must have [GraalVM installed with Native Image support](../README.md#install-native-image).
> Note: To use the Native Build Tools, first install GraalVM. The easiest way to install GraalVM is to use the [GraalVM JDK Downloader](https://github.com/graalvm/graalvm-jdk-downloader): `bash <(curl -sL https://get.graalvm.org/jdk)`.
## Prepare a Demo Application

Expand Down Expand Up @@ -160,15 +161,15 @@ git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-d
Also, remove the dependency on `guava` that will not be used.
The next steps will be focused what you should do to enable the Native Image Gradle plugin.
The next steps demonstrate what you should do to enable the [Native Image Gradle plugin](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html).
7. Register the Native Image Gradle plugin. Add the following to `plugins` section of your project’s _build.gradle_ file:
```xml
plugins {
// ...
id 'org.graalvm.buildtools.native' version '0.9.12'
id 'org.graalvm.buildtools.native' version '0.9.18'
}
```
The plugin discovers which JAR files it needs to pass to the `native-image` builder and what the executable main class should be.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We recommend that you follow the instructions and create the application step-by
git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-demo/fortune
```

> You must have [GraalVM installed with Native Image support](../README.md#install-native-image).
> Note: To use the Native Build Tools, first install GraalVM. The easiest way to install GraalVM is to use the [GraalVM JDK Downloader](https://github.com/graalvm/graalvm-jdk-downloader): `bash <(curl -sL https://get.graalvm.org/jdk)`.
## Prepare a Demo Application

Expand Down Expand Up @@ -204,16 +204,16 @@ git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-d

```xml
<properties>
<native.maven.plugin.version>0.9.12</native.maven.plugin.version>
<native.maven.plugin.version>0.9.18</native.maven.plugin.version>
<junit.jupiter.version>5.8.1</junit.jupiter.version>
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
<imageName>fortune</imageName>
<mainClass>demo.Fortune</mainClass>
</properties>
```
The statements "hardcoded" plugin versions and the entry point class to your application.
The next steps will show you how enable the Maven plugin for GraalVM Native Image.
The statements "hardcoded" plugin versions and the entry point class to your application.
The next steps demonstrate what you should do to enable the [Native Image Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html).

6. Register the Maven plugin for GraalVM Native Image, `native-maven-plugin`, in the profile called `native` by adding the following to the _pom.xml_ file:
```xml
Expand Down Expand Up @@ -263,7 +263,7 @@ git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-d
```
The plugin discovers which JAR files it needs to pass to the `native-image` builder and what the executable main class should be. With this plugin you can already build a native executable directly with Maven by running `mvn -Pnative package` (if your application does not call any methods reflectively at run time).

This demo application is a little more complicated than `HelloWorld`, and and [requires metadata](../ReachabilityMetadata.md) before building a native executable. You do not have to configure anything manually: the Native Image Maven plugin can generate the required metadata for you by injecting the [Java agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support) at package time. The agent is disabled by default, and can be enabled in project's _pom.xml_ file or via the command line.
This demo application is a little more complicated than `HelloWorld`, and [requires metadata](../ReachabilityMetadata.md) before building a native executable. You do not have to configure anything manually: the Native Image Maven plugin can generate the required metadata for you by injecting the [Java agent](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support) at package time. The agent is disabled by default, and can be enabled in project's _pom.xml_ file or via the command line.
- To enable the agent via the _pom.xml_ file, specify `<enabled>true</enabled>` in the `native-maven-plugin` plugin configuration:

```xml
Expand Down Expand Up @@ -336,7 +336,7 @@ git clone https://github.com/graalvm/graalvm-demos && cd graalvm-demos/fortune-d
```
When the command completes a native executable, _fortune_, is created in the _/target_ directory of the project and ready for use.

The executable's name is derived from the artifact ID, but you can specify any custom name in the `native-maven-plugin` plugin within a <configuration> node:
The executable's name is derived from the artifact ID, but you can specify any custom name in `native-maven-plugin` within a `<configuration>` node:
```xml
<configuration>
Expand Down

0 comments on commit a3bf346

Please sign in to comment.