Reputation: 8746
I understand that you can force a Test task to run by adding something like below to build.gradle
:
tasks.withType( Test ) {
outputs.upToDateWhen { false }
}
However, that doesn't seem to apply to a Test task that is defined inside a task rule. Specifically, I have a task rule as below:
tasks.addRule("Pattern: single<ID>: Run single test.") { String taskName ->
if (taskName.startsWith("single")) {
String pattern = taskName - 'single'
task(taskName, type: Test ) {
outputs.upToDateWhen { false }
include pattern
}
}
}
However, even though I have the first block above in my build.gradle
, the task rule always finishes without doing anything. Below is an example output:
$ gradle cleanTest singleBuildInfoScenario000001
:cleanTest UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:singleBuildInfoScenario000001 UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.868 secs
So, how can I have the corresponding test to run when I use the task rule?
Thank you very much.
Upvotes: 1
Views: 1009
Reputation: 123960
I think singleBuildInfoScenario000001
is up-to-date because it doesn't have any tests to run. (Running with --info
might give more information.) Looks like the task is missing some configuration information such as classpath
and testClassesDir
. For an example on how to configure a Test
task from scratch, see samples/java/withIntegrationTests
in the full Gradle distribution.
Upvotes: 1