Reputation: 81
I created a Gradle task in Java:
class TestTask extends Exec {
public TestTask() {
doLast(new Action<Object>(){
@Override
public void execute(Object task) {
System.out.println("Should be last ");
}
});
doFirst(new Action<Object>(){
@Override
public void execute(Object task) {
System.out.println("Should be first ");
}
});
commandLine("echo", "Should be between");
}
}
Executing this task, I expect to get
Should be first
Should be between
Should be last
but instead I get
Should be between
Should be first
Should be last
I am in the process of converting a plugin from Groovy to Java, and in Groovy the processing order was as expected when defined like this:
task dofirsttest(type: Exec) {
doFirst{
println "Should be first"
}
doLast{
println "Should be last"
}
commandLine "echo", "Should be between"
}
Is there something wrong with my task?
Upvotes: 2
Views: 1289
Reputation: 2921
commandLine("echo", "Should be between");
is in the configuration phase of the task. So it will be executed first. Have a look at: https://docs.gradle.org/current/userguide/build_lifecycle.html
Upvotes: 2