Skip to content

Commit db5e3d9

Browse files
committed
add documentation for new maven switches
1 parent 6d8d205 commit db5e3d9

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ This works similarly to `JAVA_TOOL_OPTIONS`, where the value of the environment
232232

233233
Learn more about Native Image build configuration https://www.graalvm.org/reference-manual/native-image/overview/BuildConfiguration/[on the website].
234234

235+
=== Build, but not execute native tests
236+
237+
During a transition phase, it is often useful to build tests but not execute them. This allows inspection of the generated test image without failing the build when the tests do not execute successfully.
238+
239+
If you wish to build, but not execute, the native tests, invoke Maven with the `-DskipTestExecution` switch or set the value in the plugin configuration.
240+
241+
=== Skip modules without native tests in multi-module builds
242+
243+
Multi-module projects where only some sub-modules contain native tests need to skip test execution for any module that do not contain native tests. Skip test execution for modules by setting the `<failNoTests>` configuration to `false` or providing `-DfailNoTests=false` on the command line.
244+
235245
[[gather-execution-profiles]]
236246
=== Gather Execution Profiles and Build Optimized Images
237247

docs/src/docs/asciidoc/maven-plugin.adoc

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ The following configuration options are available:
6161
----
6262
<skipNativeTests>true</skipNativeTests>
6363
----
64+
`<skipTestExecution>`::
65+
Skips execution of native tests. If set to true, the plugin will create the native image for the tests but will not execute the tests. This allows the creation of the native image for testing even when tests don't fully execute or tests fail. Otherwise, the build stops at the first test failure. To skip only the execution of the native image compiled tests, add:
66+
[source,xml, role="multi-language-sample"]
67+
----
68+
<skipNativeTests>true</skipNativeTests>
69+
----
70+
`<failNoTests>`::
71+
Fails the build if no tests were found. In multi-module builds, there are often modules that have no tests (for example, a documentation module ) or where tests are enabled or disabled by profiles (such as slow tests, e2e tests, etc.). This switch allows for a global configuration of the native plugin and then allows you to skip any modules where no tests are present by changing this setting to false in the sub-module. This allows such multi-module projects to build successfully. To avoid failing the build in a module where no tests are present, add:
72+
[source,xml, role="multi-language-sample"]
73+
----
74+
<failNoTests>false</failNoTests>
75+
----
6476
`<debug>`::
6577
If you want to enable generation of debugging information, add:
6678
[source,xml, role="multi-language-sample"]
@@ -686,6 +698,76 @@ For example, you might wish to disable only native testing support for use cases
686698
- Your library or application uses a testing framework that is not supported on the JUnit Platform.
687699
- You need to use the <<agent-support, agent>> when running tests on the JVM but do not wish to run those same tests as native code.
688700

701+
[[control-test-execution]]
702+
=== Controlling test execution
703+
704+
==== Build, but not execute native tests
705+
706+
During a transition phase, it is often useful to build tests but not execute them. This allows inspection of the generated test image without failing the build when the tests do not execute successfully.
707+
708+
If you wish to build, but not execute, the native tests, invoke Maven with the `-DskipTestExecution` flag. This flag is specific to Native Build Tools.
709+
710+
[source,bash, role="multi-language-sample"]
711+
----
712+
./mvnw -Pnative -DskipTestExecution package
713+
----
714+
715+
Alternatively, set `<skipTestExecution>` to `true` in the plugin configuration:
716+
717+
[source,xml, role="multi-language-sample"]
718+
----
719+
<configuration>
720+
<skipTestExecution>true</skipTestExecution>
721+
</configuration>
722+
----
723+
724+
This will still build the native test image but skips execution of tests as native code.
725+
726+
==== Skip modules without native tests in multi-module builds
727+
728+
In multi-module projects where only some sub-modules contain native tests, you need to skip test execution for any module that does not contain native tests. Any module which should contain tests, but does not, should fail the build.
729+
730+
Skip test execution for modules by configuring the `<failNoTests>` configuration option for the full build and then overriding it in modules where the default behavior is not desired.
731+
732+
If the majority of the sub-modules should contain native tests, nothing needs to be configured globally since this is the default behavior for the native plugin.
733+
734+
For sub-modules that do not contain native tests but should not fail the build, add this to the module's _pom.xml_ in the module in the `<plugins>` section:
735+
736+
[source,xml, role="multi-language-sample"]
737+
----
738+
<plugin>
739+
<groupId>org.graalvm.buildtools</groupId>
740+
<artifactId>native-maven-plugin</artifactId>
741+
<configuration>
742+
<failNoTests>false</failNoTests>
743+
</configuration>
744+
</plugin>
745+
----
746+
747+
If only a few sub-modules contain native tests, add this configuration setting to the main plugin configuration:
748+
749+
[source,xml, role="multi-language-sample"]
750+
----
751+
<configuration>
752+
<failNoTests>false</failNoTests>
753+
</configuration>
754+
----
755+
756+
and then override this in any sub-module that should have native tests by adding this to the module in the `<plugins>` section:
757+
758+
[source,xml, role="multi-language-sample"]
759+
----
760+
<plugin>
761+
<groupId>org.graalvm.buildtools</groupId>
762+
<artifactId>native-maven-plugin</artifactId>
763+
<configuration>
764+
<failNoTests>true</failNoTests>
765+
</configuration>
766+
</plugin>
767+
----
768+
769+
For testing from the command line, the `-DfailNoTests=false` flag is also supported directly:
770+
689771
[[metadata-support]]
690772
== GraalVM Reachability Metadata Support
691773

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,24 @@ public class NativeTestMojo extends AbstractNativeImageMojo {
9999
@Parameter(property = "skipNativeTests", defaultValue = "false")
100100
private boolean skipNativeTests;
101101

102+
/**
103+
* Skips execution of native tests. If set to true, the plugin will create the native image for the tests but do not execute the tests.
104+
* This allows the creation of the native image for testing even if they don't fully execute / tests fail.
105+
* Otherwise, the build stops at the first test failure.
106+
*
107+
* @since 0.11.1
108+
*/
102109
@Parameter(property = "skipTestExecution", defaultValue = "false")
103110
private boolean skipTestExecution;
104111

112+
/**
113+
* Fail the build if no tests were found. In multi-module builds, there are often modules that have no tests (e.g. documentation)
114+
* or tests are enabled/disabled by profiles (slow tests, e2e tests etc.). This switch allows for a global configuration of the
115+
* native plugin and then skip any modules where no tests are present by changing this setting to false in the sub-module.
116+
* This allows such multi-module projects to build successfully.
117+
*
118+
* @since 0.11.1
119+
*/
105120
@Parameter(property = "failNoTests", defaultValue = "true")
106121
private boolean failNoTests;
107122

0 commit comments

Comments
 (0)