-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4600 from geoand/junit-platform-gradle
Fix gradle - junit5 integration templates and instructions
- Loading branch information
Showing
9 changed files
with
105 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package io.quarkus.gradle; | ||
|
||
import java.util.Collections; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.artifacts.ConfigurationContainer; | ||
import org.gradle.api.plugins.BasePlugin; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradle.api.plugins.JavaPluginConvention; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.SourceSetContainer; | ||
import org.gradle.api.tasks.SourceSetOutput; | ||
import org.gradle.api.tasks.TaskContainer; | ||
import org.gradle.api.tasks.testing.Test; | ||
import org.gradle.util.GradleVersion; | ||
|
@@ -17,6 +24,7 @@ | |
import io.quarkus.gradle.tasks.QuarkusListExtensions; | ||
import io.quarkus.gradle.tasks.QuarkusNative; | ||
import io.quarkus.gradle.tasks.QuarkusTestConfig; | ||
import io.quarkus.gradle.tasks.QuarkusTestNative; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ståle Pedersen</a> | ||
|
@@ -52,11 +60,38 @@ private void registerTasks(Project project) { | |
quarkusBuild.dependsOn(classesTask); | ||
}); | ||
|
||
tasks.create("buildNative", QuarkusNative.class).dependsOn(quarkusBuild); | ||
Task buildNative = tasks.create("buildNative", QuarkusNative.class).dependsOn(quarkusBuild); | ||
|
||
// set up the source set for the testNative | ||
JavaPluginConvention javaPlugin = project.getConvention().findPlugin(JavaPluginConvention.class); | ||
if (javaPlugin != null) { | ||
SourceSetContainer sourceSets = javaPlugin.getSourceSets(); | ||
SourceSet nativeTestSourceSet = sourceSets.create("native-test"); // this name has to be the same as the directory in which the tests reside | ||
SourceSetOutput mainSourceSetOutput = sourceSets.getByName("main").getOutput(); | ||
SourceSetOutput testSourceSetOutput = sourceSets.getByName("test").getOutput(); | ||
nativeTestSourceSet.setCompileClasspath( | ||
nativeTestSourceSet.getCompileClasspath().plus(mainSourceSetOutput).plus(testSourceSetOutput)); | ||
nativeTestSourceSet.setRuntimeClasspath( | ||
nativeTestSourceSet.getRuntimeClasspath().plus(mainSourceSetOutput).plus(testSourceSetOutput)); | ||
|
||
// create a custom configuration to be used for the dependencies of the testNative task | ||
ConfigurationContainer configurations = project.getConfigurations(); | ||
configurations.maybeCreate("nativeTestImplementation").extendsFrom(configurations.findByName("implementation")); | ||
configurations.maybeCreate("nativeTestRuntimeOnly").extendsFrom(configurations.findByName("runtimeOnly")); | ||
|
||
Task testNative = tasks.create("testNative", QuarkusTestNative.class).dependsOn(buildNative); | ||
testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName("test"))); | ||
|
||
tasks.getByName("check").dependsOn(testNative); | ||
} | ||
|
||
// Quarkus test configuration task which should be executed before any Quarkus test | ||
final QuarkusTestConfig quarkusTestConfig = tasks.create("quarkusTestConfig", QuarkusTestConfig.class); | ||
tasks.withType(Test.class).forEach(t -> t.dependsOn(quarkusTestConfig)); | ||
tasks.withType(Test.class).forEach(t -> { | ||
// Quarkus test configuration task which should be executed before any Quarkus test | ||
t.dependsOn(quarkusTestConfig); | ||
// also make each task use the JUnit platform since it's the only supported test environment | ||
t.useJUnitPlatform(); | ||
}); | ||
} | ||
|
||
private void verifyGradleVersion() { | ||
|
21 changes: 21 additions & 0 deletions
21
devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestNative.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.gradle.tasks; | ||
|
||
import org.gradle.api.plugins.JavaPluginConvention; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.SourceSetContainer; | ||
import org.gradle.api.tasks.testing.Test; | ||
|
||
public class QuarkusTestNative extends Test { | ||
|
||
public QuarkusTestNative() { | ||
setDescription("Runs native image tests"); | ||
setGroup("verification"); | ||
|
||
JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class); | ||
SourceSetContainer sourceSets = javaPlugin.getSourceSets(); | ||
SourceSet sourceSet = sourceSets.findByName("native-test"); | ||
|
||
setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); | ||
setClasspath(sourceSet.getRuntimeClasspath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters