War task overrides test tasks in subprojects

I have “test” tasks in subprojects:

apply plugin: 'java'

test {
  description = 'Runs tests that are marked as @FastTest.'

  useJUnit {  includeCategories 'category.FastTest'  }
}

If I add “war” task to the root project:

apply plugin: 'war'

, it overrides test tasks in subprojects, e.g. it ignores my “test” task properties. How do I suppress “war” task overriding “test” tasks?

This does not sound like the expected behaviour.

Which Gradle version are you using?

Can you provide a minimal example that allows me to reproduces the problem?

I think what you’re witnessing is this:

If you don’t have a test task in the root project, calling gradle test will invoke the test tasks in all the subprojects.

Since you have applied the war plugin to the root project you are adding an explicit test task to the root so you are not getting the same behaviour.

Try running
gradle :somesubproject:test
I’m assuming you run the tests as expected for somesubproject

Solution 1: Don’t apply war to root, instead have the war as a sibling to the java libraries.

Solution 2: Wire the subproject test tasks into the root project’s DAG.

eg:

subprojects {
   rootProject.test.dependsOn test
} 

I feel that option 1 is the orthodox/normal approach

Tried, did not help.

Tried, did not help.