Gradle phases and task types

Hello,
I am trying to understand how gradle phases work when I add a type in my task.

I understand that there are 3 phases: 1.Initialization 2.Configuration 3.Execution
and that the Initialization and Configuration phases of all tasks are running every time you are executing a task, regardless of which task you are running.

I have created the below task:

task functionalTests(type: Test) {
group JavaBasePlugin.VERIFICATION_GROUP
description ‘Runs the functional tests.’
include ‘/funcionaltests/tests/
}

I was expecting that because I haven’t add a “doLast” or “doFirst” the “include ‘/funcionaltests/tests/’” would run during the Configuration phase, but I see that it is running at the Execution phase.

Does the “include” add this step into the Execution phase?
I observed the same with the “type: Exec” and the “commandLine”.

The line include '/functionaltests/tests/' executes in the configuration phase. However, all that is doing is adding the path to a list of includes for the task (configuration). The Test task type has a task action (like what you would add with doFirst or doLast) that runs the actual tests in the execution phase that uses this configured value. The include '/functionaltests/tests/' doesn’t actually run tests. It just configures the task for when it does.

1 Like