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
@@ -299,7 +298,7 @@ To enable the agent via the command line, pass the `-Pagent` option when running
299
298
300
299
[source,bash, role="multi-language-sample"]
301
300
----
302
-
./gradlew -Pagent nativeRun
301
+
./gradlew -Pagent run
303
302
----
304
303
305
304
[TIP]
@@ -329,10 +328,12 @@ graalvmNative {
329
328
}
330
329
----
331
330
332
-
From that point on, commands you execute will run with the agent attached.
331
+
From that point on, commands like `run` or `test` will be executed with the agent attached.
333
332
By default, the agent creates the metadata in the _build/native/agent-output_ directory.
334
333
335
-
Step 2: **Copy the generated metadata** from the default location, _build/native/agent-output_, to the resources directory, for example, _resources/META-INF/_.
334
+
Step 2: **Copy the generated metadata** from the default location, _build/native/agent-output_, to the resources directory, for example, _resources/META-INF/native-image_.
335
+
Native Image automatically takes metadata from that location.
336
+
336
337
To do that with Gradle, configure and run the `metadataCopy` task.
337
338
338
339
Add a new task named `metadataCopy` inside the `graalvmNative` block.
@@ -343,8 +344,8 @@ Your `agent` configuration should look like this:
Copy file name to clipboardexpand all lines: docs/src/docs/asciidoc/end-to-end-maven-guide.adoc
+35-9
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ For convenience, you can create a Maven profile and add the plugin into it:
73
73
</profiles>
74
74
----
75
75
76
-
Replace `{maven-plugin-version}` with the latest released version.
76
+
Replace `maven-plugin-version` with the latest released version.
77
77
All plugin versions are listed https://github.com/graalvm/native-build-tools/releases[here].
78
78
79
79
The `<mainClass>` tag provides the path to the application main class (the main entry point).
@@ -182,6 +182,17 @@ The tests are compiled ahead of time and executed as native code.
182
182
</dependency>
183
183
----
184
184
185
+
- Add surefire plugin into plugins section of your profile:
186
+
187
+
[source,xml, role="multi-language-sample"]
188
+
----
189
+
<plugin>
190
+
<groupId>org.apache.maven.plugins</groupId>
191
+
<artifactId>maven-surefire-plugin</artifactId>
192
+
<version>3.0.0</version>
193
+
</plugin>
194
+
----
195
+
185
196
- Run the tests:
186
197
187
198
[source,bash, role="multi-language-sample"]
@@ -344,14 +355,21 @@ In such cases, additional metadata is required.
344
355
The easiest way to collect the missing metadata is by using the https://www.graalvm.org/reference-manual/native-image/metadata/AutomaticMetadataCollection/[Tracing Agent].
345
356
This agent tracks all usages of dynamic features during application execution on the JVM and generates the necessary configuration.
346
357
358
+
[NOTE]
359
+
====
360
+
In this guide we will show you how to generate metadata from your tests.
361
+
Generating metadata from your main application requires <<maven-plugin.adoc#agent-support-running-application,more configuring>>.
362
+
Other than that, the guide remains the same, except that you use the `package` phase instead of the `test` phase.
363
+
====
364
+
347
365
The agent is disabled by default.
348
366
You can enable it on the command line or in _pom.xml_.
349
367
350
368
To enable the agent via the command line, pass the `-Dagent=true` option when running Maven:
351
369
352
370
[source,bash, role="multi-language-sample"]
353
371
----
354
-
mvn -Pnative -Dagent=true package
372
+
mvn -Pnative -Dagent=true test
355
373
----
356
374
357
375
[TIP]
@@ -366,7 +384,6 @@ Step 1: **Enable the agent** by setting `<agent>` to `true` in the `native` prof
366
384
[source,xml, role="multi-language-sample"]
367
385
----
368
386
<configuration>
369
-
<mainClass>org.example.Main</mainClass>
370
387
<agent>
371
388
<enabled>true</enabled>
372
389
</agent>
@@ -375,7 +392,9 @@ Step 1: **Enable the agent** by setting `<agent>` to `true` in the `native` prof
375
392
From that point on, commands you execute will run with the agent attached.
376
393
By default, the agent creates the metadata in the _target/native/agent-output_ directory.
377
394
378
-
Step 2: **Copy the generated metadata** from the default location, _target/native/agent-output/_, to the resources directory, for example, _resources/META-INF/_.
395
+
Step 2: **Copy the generated metadata** from the default location, _target/native/agent-output/_, to the resources directory, for example, _resources/META-INF/native-image_.
396
+
Native Image automatically takes metadata from that location.
397
+
379
398
To do that with Maven, configure and run the `metadataCopy` task.
380
399
381
400
Add a new task named `metadataCopy` inside the `agent` block that you added in step 1.
@@ -384,13 +403,12 @@ Your `agent` configuration should look like this:
mvn -Pnative -Dagent=true test native:metadata-copy
409
427
----
410
428
411
-
Step 4: Finally, **build the native image with the metadata** and run:
429
+
Step 4: Finally, you can proceed without the agent and **build the native image with the metadata from `META-INF` directory**.
430
+
From that point on, you can run your tests with:
412
431
413
432
[source,bash, role="multi-language-sample"]
414
433
----
415
-
mvn -Pnative package
434
+
mvn -Pnative test
416
435
----
417
436
418
437
If your native image is successfully build, but still fails at run time, check the troubleshooting guide https://www.graalvm.org/reference-manual/native-image/guides/troubleshoot-run-time-errors/[Troubleshoot Native Image Run-Time Errors].
@@ -453,6 +472,13 @@ When running on GraalVM for JDK 21, pass the `-H:+BuildReport` option instead to
453
472
454
473
All the monitoring and debugging tools https://www.graalvm.org/reference-manual/native-image/debugging-and-diagnostics/[listed on the website], can be enabled in the plugin configuration using `<buildArgs>`.
455
474
475
+
You will see the output of these tools among generated artifacts when you run:
476
+
477
+
[source,bash, role="multi-language-sample"]
478
+
----
479
+
mvn -Pnative -DskipNativeTests package
480
+
----
481
+
456
482
=== Learn more
457
483
458
484
To continue learning, refer to the <<changelog.adoc#,extensive reference documentation for the GraalVM Native Image Maven plugin>>.
0 commit comments