Skip to content

Commit ee9a953

Browse files
committed
Add flag for skipping tests on JVM in Gradle plugin
1 parent fd64cd4 commit ee9a953

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
# Project versions
3-
nativeBuildTools = "0.11.1-SNAPSHOT"
3+
nativeBuildTools = "0.11.1-DRY"
44
metadataRepository = "0.3.22"
55

66
# External dependencies

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/NativeImagePlugin.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,16 @@ public void registerTestBinary(Project project,
680680
test.getOutputs().dir(testList);
681681
// Set system property read by the UniqueIdTrackingListener.
682682
test.systemProperty(JUNIT_PLATFORM_LISTENERS_UID_TRACKING_ENABLED, true);
683-
test.systemProperty(JUNIT_PLATFORM_DRY_RUN_ENABLED, true);
683+
684+
// Set system property to skip execution of JVM tests before native tests
685+
if (shouldSkipJVMTests(testOptions.getSkipJVMTests().get())) {
686+
if (graalExtension.getAgent().getEnabled().get()) {
687+
throw new IllegalStateException("Native Image Agent and skipJVMTests cannot be used at the same time.");
688+
}
689+
690+
test.systemProperty(JUNIT_PLATFORM_DRY_RUN_ENABLED, true);
691+
}
692+
684693
TrackingDirectorySystemPropertyProvider directoryProvider = project.getObjects().newInstance(TrackingDirectorySystemPropertyProvider.class);
685694
directoryProvider.getDirectory().set(testListDirectory);
686695
test.getJvmArgumentProviders().add(directoryProvider);
@@ -715,6 +724,15 @@ public void registerTestBinary(Project project,
715724
});
716725
}
717726

727+
private boolean shouldSkipJVMTests(boolean valueFromBuildFile) {
728+
String valueFromCommandLine = System.getProperty("skipJVMTests");
729+
if (valueFromCommandLine == null) {
730+
return valueFromBuildFile;
731+
}
732+
733+
return Boolean.parseBoolean(valueFromCommandLine);
734+
}
735+
718736
/**
719737
* Returns a provider which prefers the CLI arguments over the configured
720738
* extension value.

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/dsl/NativeImageCompileOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ public interface NativeImageCompileOptions {
229229
@Nested
230230
DeprecatedAgentOptions getAgent();
231231

232+
/**
233+
* Gets value which determines if JVM tests run should be skipped.
234+
*
235+
* @return true if JVM tests should be skipped
236+
*/
237+
@Input
238+
Property<Boolean> getSkipJVMTests();
239+
232240
/**
233241
* When set to true, the compiled binaries will be generated with PGO instrumentation
234242
* support.

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/BaseNativeImageOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public BaseNativeImageOptions(String name,
276276
getSharedLibrary().convention(false);
277277
getImageName().convention(defaultImageName);
278278
getUseFatJar().convention(false);
279+
getSkipJVMTests().convention(false);
279280
getPgoInstrument().convention(false);
280281
DirectoryProperty pgoProfileDir = objectFactory.directoryProperty();
281282
pgoProfileDir.convention(layout.getProjectDirectory().dir("src/pgo-profiles/" + name));

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/DelegatingCompileOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public DeprecatedAgentOptions getAgent() {
166166
return options.getAgent();
167167
}
168168

169+
@Override
170+
public Property<Boolean> getSkipJVMTests() {
171+
return options.getSkipJVMTests();
172+
}
173+
169174
@Override
170175
public Property<Boolean> getPgoInstrument() {
171176
return options.getPgoInstrument();

0 commit comments

Comments
 (0)