I have two tasks Task-A
and Task-B
This is my Task-A
task Task-A () {
doLast {
def fileName = _.property('fileName')
if (fileName !=null) {
println 'success'
}
}
}
My Task-B is dependent on Task-A and I should make it dependent only on the Condition that _.property('fileName')
should exist and should not be null
So I wrote my Task-B this way
task Task-B () {
doFirst {
def fileName = _.property('fileName')
if (fileName !=null) {
dependsOn 'Task-A'
}
}
}
It throws an Error
Cannot call Task.dependsOn(Object...) on task ':Task-B' after task has started execution.
How to execute dependsOn
on a condition ?
Using Command Line Flags Task :compileTestJava > Task :processTestResources NO-SOURCE > Task :testClasses > Task :test > ... To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build.
The doLast creates a task action that runs when the task executes. Without it, you're running the code at configuration time on every build. Both of these print the line, but the first one only prints the line when the testTask is supposed to be executed.
Defining Tasks. Task is a keyword which is used to define a task into build script. Take a look at the following example which represents a task named hello that prints tutorialspoint. Copy and save the following script into a file named build.
You must set dependsOn
directives during the configuration phase
try :
task Task-B () {
def fileName = _.property('fileName')
if (fileName !=null) {
dependsOn 'Task-A'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With