Skip to content

Commit f393f7a

Browse files
committed
Final snippet adjustments
1 parent 450b9b1 commit f393f7a

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

docs/src/docs/asciidoc/end-to-end-gradle-guide.adoc

+11-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ graalvmNative {
102102
binaries.main {
103103
// options to configure the main binary
104104
imageName = 'application'
105-
mainClass = 'org.test.Main'
105+
mainClass = 'org.example.Main'
106106
buildArgs.add('-O3') // enables additional compiler optimizations
107107
}
108108
binaries.test {
@@ -120,11 +120,10 @@ graalvmNative {
120120
// common options
121121
verbose.set(true)
122122
}
123-
124123
binaries.main {
125124
// options to configure the main binary
126125
imageName.set('application')
127-
mainClass.set('org.test.Main')
126+
mainClass.set('org.example.Main')
128127
buildArgs.add('-O3') // enables additional compiler optimizations
129128
}
130129
@@ -299,7 +298,7 @@ To enable the agent via the command line, pass the `-Pagent` option when running
299298

300299
[source,bash, role="multi-language-sample"]
301300
----
302-
./gradlew -Pagent nativeRun
301+
./gradlew -Pagent run
303302
----
304303

305304
[TIP]
@@ -329,10 +328,12 @@ graalvmNative {
329328
}
330329
----
331330

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.
333332
By default, the agent creates the metadata in the _build/native/agent-output_ directory.
334333

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+
336337
To do that with Gradle, configure and run the `metadataCopy` task.
337338

338339
Add a new task named `metadataCopy` inside the `graalvmNative` block.
@@ -343,8 +344,8 @@ Your `agent` configuration should look like this:
343344
agent {
344345
enabled = true
345346
metadataCopy {
346-
inputTaskNames.add("test")
347-
outputDirectories.add("src/test/resources/META-INF/native-image/org.example")
347+
inputTaskNames.add("run")
348+
outputDirectories.add("src/main/resources/META-INF/native-image/org.example")
348349
mergeWithExisting = true
349350
}
350351
}
@@ -355,8 +356,8 @@ agent {
355356
agent {
356357
enabled.set(true)
357358
metadataCopy {
358-
inputTaskNames.add("test")
359-
outputDirectories.add("resources/META-INF/native-image/org.example")
359+
inputTaskNames.add("run")
360+
outputDirectories.add("src/main/resources/META-INF/native-image/org.example")
360361
mergeWithExisting.set(true)
361362
}
362363
}

docs/src/docs/asciidoc/end-to-end-maven-guide.adoc

+35-9
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ For convenience, you can create a Maven profile and add the plugin into it:
7373
</profiles>
7474
----
7575

76-
Replace `{maven-plugin-version}` with the latest released version.
76+
Replace `maven-plugin-version` with the latest released version.
7777
All plugin versions are listed https://github.com/graalvm/native-build-tools/releases[here].
7878

7979
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.
182182
</dependency>
183183
----
184184

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+
185196
- Run the tests:
186197

187198
[source,bash, role="multi-language-sample"]
@@ -344,14 +355,21 @@ In such cases, additional metadata is required.
344355
The easiest way to collect the missing metadata is by using the https://www.graalvm.org/reference-manual/native-image/metadata/AutomaticMetadataCollection/[Tracing Agent].
345356
This agent tracks all usages of dynamic features during application execution on the JVM and generates the necessary configuration.
346357

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+
347365
The agent is disabled by default.
348366
You can enable it on the command line or in _pom.xml_.
349367

350368
To enable the agent via the command line, pass the `-Dagent=true` option when running Maven:
351369

352370
[source,bash, role="multi-language-sample"]
353371
----
354-
mvn -Pnative -Dagent=true package
372+
mvn -Pnative -Dagent=true test
355373
----
356374

357375
[TIP]
@@ -366,7 +384,6 @@ Step 1: **Enable the agent** by setting `<agent>` to `true` in the `native` prof
366384
[source,xml, role="multi-language-sample"]
367385
----
368386
<configuration>
369-
<mainClass>org.example.Main</mainClass>
370387
<agent>
371388
<enabled>true</enabled>
372389
</agent>
@@ -375,7 +392,9 @@ Step 1: **Enable the agent** by setting `<agent>` to `true` in the `native` prof
375392
From that point on, commands you execute will run with the agent attached.
376393
By default, the agent creates the metadata in the _target/native/agent-output_ directory.
377394

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+
379398
To do that with Maven, configure and run the `metadataCopy` task.
380399

381400
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:
384403
[source,xml, role="multi-language-sample"]
385404
----
386405
<agent>
387-
<enabled>true</enabled>
388406
<metadataCopy>
389407
<disabledStages>
390408
<stage>main</stage>
391409
</disabledStages>
392410
<merge>true</merge>
393-
<outputDirectory>resources/META-INF/</outputDirectory>
411+
<outputDirectory>src/test/resources/META-INF/native-image</outputDirectory>
394412
</metadataCopy>
395413
</agent>
396414
----
@@ -405,14 +423,15 @@ Step 3: Now that the `metadataCopy` task is configured, **run the agent to colle
405423

406424
[source,bash,subs="verbatim,attributes", role="multi-language-sample"]
407425
----
408-
mvn -Pnative test native:metadata-copy
426+
mvn -Pnative -Dagent=true test native:metadata-copy
409427
----
410428

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:
412431

413432
[source,bash, role="multi-language-sample"]
414433
----
415-
mvn -Pnative package
434+
mvn -Pnative test
416435
----
417436

418437
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
453472

454473
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>`.
455474

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+
456482
=== Learn more
457483

458484
To continue learning, refer to the <<changelog.adoc#,extensive reference documentation for the GraalVM Native Image Maven plugin>>.

0 commit comments

Comments
 (0)