You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/end-to-end-gradle-guide.adoc
+16-5Lines changed: 16 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ all the way to some diagnostics tools that you can use to analyse native executa
9
9
10
10
In case you only want to see how a simple application works in practise, you can check <<quickstart-gradle-plugin.adoc#,our demo>>.
11
11
12
-
== Prerequisites
13
12
[[prerequisites]]
13
+
== Prerequisites
14
14
15
15
- Before starting, make sure that you have GraalVM installed locally. You can https://www.graalvm.org/downloads/[download Oracle GraalVM from the official website].
16
16
- In most cases you can run your Gradle project with almost any GraalVM version. All you have to do is to set `JAVA_HOME` environment variable to the release you want to use.
@@ -20,7 +20,7 @@ Note that in some cases, depending on the Gradle version you are using (https://
20
20
You can run Gradle project with any GraalVM version you should set `GRAALVM_HOME` environment variable to point to whatever GraalVM release you want, and `JAVA_HOME` environment variable to some older version (like Java 17).
21
21
This way, the Gradle plugin will build itself with Java specified in `JAVA_HOME` and your project with the version specified in `GRAALVM_HOME`.
22
22
23
-
23
+
[[adding-plugin]]
24
24
== Adding plugin
25
25
26
26
In order to use Native Image through gradle you must add the following block into your `build.gradle` file inside `plugins` block:
@@ -37,6 +37,7 @@ In order to use Native Image through gradle you must add the following block int
37
37
38
38
You can also check other versions of the plugin https://github.com/graalvm/native-build-tools/releases[here]
39
39
40
+
[[run-your-project]]
40
41
== First runs of your project
41
42
42
43
This plugin works with the application plugin and will register a number of tasks that you may want to execute.
@@ -50,6 +51,7 @@ The main tasks you may want to use are:
50
51
In the following sections you will find out how to use these tasks in practice.
51
52
52
53
54
+
[[run-tests]]
53
55
=== Run your tests
54
56
55
57
Running your tests should be a straight forward thing.
@@ -60,6 +62,7 @@ All you have to do is to write your tests under the test source (usually under _
60
62
./gradlew nativeTest
61
63
----
62
64
65
+
[[run-application]]
63
66
=== Run your application
64
67
65
68
Once you added your plugin, you can try to build native image on a simple HelloWorld application (or with your main if you are not starting from the scratch).
@@ -102,6 +105,7 @@ Once the build is finished, run the following command to execute generated Nativ
102
105
./gradlew nativeRun
103
106
----
104
107
108
+
[[run-on-jvm]]
105
109
==== Run on JVM
106
110
107
111
Note that **if you want to run your application (or maybe the native image agent later on your application) on the JVM** you should make the following changes in the `build.gradle`:
@@ -135,6 +139,7 @@ application {
135
139
Note that the added block points to the main class placed under __/src/main/java/org.example.Main.java__. User should adjust this according to its application source set.
136
140
137
141
142
+
[[configuration-options]]
138
143
== Providing configuration options
139
144
140
145
The main configuring point of this plugin is the `graalvmNative` block that you added into `build.gradle` file.
@@ -158,7 +163,7 @@ graalvmNative {
158
163
159
164
Inside these blocks you can pass the following options:
160
165
161
-
- `imageName` -The name of the native image, defaults to the project name
166
+
- `imageName` -The name of the native image
162
167
- `mainClass` - The main class to use, defaults to the application.mainClass
163
168
- `debug` - Determines if debug info should be generated, defaults to false (alternatively add --debug-native to the CLI)
164
169
- `verbose` - Add verbose output (`false` by default)
@@ -244,8 +249,8 @@ graalvmNative {
244
249
}
245
250
----
246
251
247
-
== Collecting metadata
248
252
[[collect-metadata]]
253
+
== Collecting metadata
249
254
250
255
When your test/application starts to be a bit more complex things like **reflection**, **resources**, **serialization**, **proxies** or **jni** may be required.
251
256
Since the Native Image has closed world assumption, all of these things must be known in advance during the image build.
@@ -354,6 +359,7 @@ Explanation of the `metadataCopy` block from above:
354
359
- __outputDirectories.add("resources/META-INF/native-image/org.example")__ - means that we want to copy metadata into the given directory
355
360
- __mergeWithExisting = false__ - means that we don't want to merge incoming metadata with the one that already exists on the location specified in `outputDirectories` (this makes sense since we don't have metadata on the given location already)
356
361
362
+
[[execute-metadata-copy-task]]
357
363
==== Execute metadataCopy task
358
364
359
365
Once the metadata is generated and the `metadataCopy` task is configured, you can run the task with:
@@ -467,7 +473,8 @@ For example
467
473
./gradlew -Pagent=direct nativeTest
468
474
----
469
475
470
-
==== Common options
476
+
[[common-agent-options]]
477
+
==== Common agent options
471
478
472
479
All the mentioned modes shares certain common configuration options like:
473
480
@@ -479,6 +486,7 @@ All the mentioned modes shares certain common configuration options like:
479
486
- enableExperimentalUnsafeAllocationTracing
480
487
- trackReflectionMetadata
481
488
489
+
[WARNING]
482
490
**These options are for advanced usages, and you can read more about them https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/#agent-advanced-usage[here]**.
483
491
484
492
Complete example of the agent block should look like this:
@@ -686,6 +694,7 @@ After we regenerate the metadata with the new filter, `resource-config.json` gen
686
694
As you can see there are no more entries that contain classes from `org.junit.platform.launcher` (as their condition) for example.
687
695
688
696
697
+
[[maintain-generated-metadata]]
689
698
== Maintain generated metadata
690
699
691
700
If you are a library maintainer, or your application became huge, you may consider covering most of your code with tests.
@@ -706,6 +715,7 @@ So if you modified existing metadata file(s) on the default location, please do
706
715
This way you will keep your original metadata, and add a new one.
707
716
708
717
718
+
[[reachability-metadata-repository]]
709
719
== Reachability metadata repository
710
720
711
721
Native Build Tools (both Gradle and Maven plugins) picks metadata from Reachability metadata repository to ensure your application works out-of-box (if all metadata required by your app is already contributed to the metadata repository).
- collect metadata as described https://github.com/oracle/graalvm-reachability-metadata/blob/master/docs/CollectingMetadata.md#collecting-metadata-for-a-library[here]
738
748
- create a pull request and fill the checklist
739
749
750
+
[[track-diagnostics]]
740
751
== Track diagnostics
741
752
742
753
If you want to explore details about native images you are generating, you can add:
0 commit comments