Skip to content

Commit 6494d23

Browse files
committed
Adds two new switches to the maven test goal
- skipTestExecution (boolean), default is false If true, create the native image for the tests but do not execute it. This allows the creation of the native images for testing even if they don't fully execute / tests fail. Otherwise, the build would stop at the first test failure. - failNoTests (boolean), default is true If true, fail building if no tests were found. In multi-module builds, there are often modules that have no tests (documentation) or tests are enabled/disabled by profiles (slow tests, e2e tests etc.). This switch allows for a concise configuraiton of the native plugin and then skipping modules where no tests were run without failing the build.
1 parent 2723791 commit 6494d23

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

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

102+
@Parameter(property = "skipTestExecution", defaultValue = "false")
103+
private boolean skipTestExecution;
104+
105+
@Parameter(property = "failNoTests", defaultValue = "true")
106+
private boolean failNoTests;
107+
102108
@Override
103109
protected void populateApplicationClasspath() throws MojoExecutionException {
104110
super.populateApplicationClasspath();
@@ -151,8 +157,13 @@ public void execute() throws MojoExecutionException {
151157
return;
152158
}
153159
if (!hasTestIds()) {
154-
logger.error("Test configuration file wasn't found. Make sure that test execution wasn't skipped.");
155-
throw new IllegalStateException("Test configuration file wasn't found.");
160+
if (failNoTests) {
161+
logger.error("Test configuration file wasn't found. Make sure that test execution wasn't skipped.");
162+
throw new IllegalStateException("Test configuration file wasn't found.");
163+
} else {
164+
logger.info("No tests found, skipping.");
165+
return;
166+
}
156167
}
157168

158169
logger.info("====================");
@@ -178,7 +189,10 @@ public void execute() throws MojoExecutionException {
178189
mainClass = "org.graalvm.junit.platform.NativeImageJUnitLauncher";
179190

180191
buildImage();
181-
runNativeTests(outputDirectory.toPath().resolve(NATIVE_TESTS_EXE));
192+
193+
if (!skipTestExecution) {
194+
runNativeTests(outputDirectory.toPath().resolve(NATIVE_TESTS_EXE));
195+
}
182196
}
183197

184198
private void configureEnvironment() {

0 commit comments

Comments
 (0)