There are multiple questions related to viewing gradle task dependencies, that is, given Task X, what other tasks will be triggered.
Is there a plugin to perform the opposite calculation, that is, given Task X, list all of the tasks which would cause Task X to be executed.
Related
In Windows task scheduler I have a task. For example: Test
Under that, I have 3 actions.
Problem is all 3 actions execute at the same time.
I have a requirement that each actions starts only after the previous one ends.
Is there way we can set these conditions?
We have a scheduler that allots a service a time slice of about 30 seconds every so often. That service must execute a list of tasks, but it takes more than 30 seconds to execute all the tasks. Therefore it has to do those tasks over multiple calls.
Under these circumstances, how does one ensure that every task is executed, and no task is executed more than once? (The list of tasks can change between calls, they're not all distinct and the list of tasks itself cannot be modified by the service, each task, even those distinct have to be executed, you can save to disk, so you can persist a list of tasks, and a task is done if it's deleted by the user.)
Is there a way to get the task graph or even just the task names during the Gradle configuration phase?
We have some code in buildSrc and it would be convenient to take some actions based on the tasks that will be run. If I try to get the task graph in our buildSrc code then I receive an exception with Task information is not available, as this task execution graph has not been populated.. Is there any way to get an idea of which tasks are to be executed prior the the execution graph being populated?
I was thinking of parsing the Gradle command line to check for task names there but that is brittle and seems less than ideal.
You should rely as much as possible on Gradle and not try to reinvent the wheel when it comes to figuring out which tasks will run.
From a programmatic point of view:
To list all possible tasks in the project: project.tasks
To obtain the task graph: gradle.taskGraph
For example, at the end of the configuration phase, you could call methods that are in your buildSrc:
gradle.taskGraph.whenReady { taskGraph ->
// Call your methods here using the task graph
}
Gradle generally determines task order itself, which is often fine, but sometimes you need task ordering.
Based on the the User Guide and other discussion here it appears there are two basic ways to order tasks:
Using dependencies, i.e. taskB depends on taskA, so taskA will execute first.
Adding a new parent task, and using mustRunAfter as a constraint to sequence the subtasks.
However there are some situations where both approaches seem troublesome.
Example 1:
In in daily task run by some continuous build system, you might have a sequence:
setupTask1 setupTask2 build test sendReport
Now, you can actually script this sequence externally, by passing these tasks on the gradle command line, i.e.
gradle setupTask1 setupTask2 build test sendReport
But if you want to write (and document) this sequence in the build file itself (rather than externally), are you required to create a new task, then add four new ordering constraints?
Example 2:
Now imagine we have
startServer1 startServer2 integrationTest tearDownServer2 tearDownServer1
In this case, we want sequencing, but also control over failures, since if integrationTest fails, you still want the teardown steps to occur. Then we not only need mustRunAfter, we also have to add finalizedBy. And do we add the finalizer on integrationTest? What about if we add more tests that need such a harness? What if we want tearDownServer1 to be sequenced relative to tearDownServer2?
In summary, sequencing seems very clumsy, at least to a Gradle novice. In some cases, it might be more elegant simply to sequence things directly in a more imperative way. Am I missing something? Is there a better approach here?
It is (highly) advised to use the (already named) solutions to use dependsOn and mustRunAfter.
If you are fine with invoking tasks rather than depending on tasks, you could try the following possible solution for example one. Create a task that executes the tasks in sequence. You would get something like this:
task dailyCIJob << {
[setupTask1, setupTask2, build, test, sendReport].each {
it.execute()
}
}
There are two, both not satisfying, solutions for example two:
Use the --continue Gradle commanline argument. This will make Gradle continue if a task fails.
Also you seem to be able to set a ignoreFailures boolean property per (test) task.
I have separated a big Hudson job into smaller jobs. Job A does the main build and Job B does another build with a different configuration. I have configured Hudson, so that the A triggers B and that works fine, the problem is that Job A has the original build number and B has started from 1.
My question is: Is it possible to pass the BUILD_NUMBER environment variable somehow from Job A to Job B? The build number is used in the build artifact names, hence it would be nice to have the numbers match between artifacts.
Thanks.
Use the parametrized Parameterized Trigger Plugin, which will allow you to pass the build number from A to B. You will not be able to actually set the build number in job B, but you will have the build number from A to generate your version number.
If you want to synchronize the build number, you can edit the file nextBuildNumber in the job directory to match the number from job A. Be aware that these numbers will drift apart over the time since when A fails B will not be started.
EDIT I just stumbled across the Next Build Number Plugin. Have a look, If this one helps you.