Detect if task will be executed

hi

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
}

greetz

You can make use the TaskExecutionGraph:
https://docs.gradle.org/7.0/javadoc/org/gradle/api/execution/TaskExecutionGraph.html

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.

Gruß