How can I disable tests depending on the task, that is being called?

I have a multi-project build. In the root buildscript we have a task buildAllComponents, which builds all subproject jars and assembles them in a certain way. The test tasks are disabled, since we execute unit tests in our IDE directly. However, we have another task integrationBuild, which is executed on our integration server. The task is dependend on buildAllComponents. How can we now enable the test tasks, iff integrationBuild is called, but not when buildAllComponents is called directly (and locally)?

You can inspect the task graph to make this determination.

test {

gradle.taskGraph.whenReady { graph->

enabled graph.hasTask(’:integrationBuild’)

}

}