Detect if task will be executed


How can I detect in the configure phase if a task will be executed? Example:

gradle check
(or gradle build)

build will call check, check will call test. How can I detect if the test task will be executed?

if (taskWillBeExecuted(“test”)) {
// add another task or do something expensive


You can make use the TaskExecutionGraph:

You can get an instance of it via project.gradle.

Does this help?

hi StefMa

thanks for your reply. This does not work in the configuration phase. It works in the execution phase and in the taskGraph.whenReady closure.
My task is to add projects in settings.gradle if a task is specified. Or to add the test-jar if the test task is present.