在运行时跳过gradle中的任务
我有两个简单的任务在运行时跳过gradle中的任务,gradle,Gradle,我有两个简单的任务 task initdb { println 'database' } task profile(dependsOn: initdb) << { println 'profile' } task initdb{println'数据库} 任务配置文件(dependsOn:initdb)此行为的原因是initdb未正确声明。它缺少一个我想在profile之前执行initdb任务代码,但是通过调用gradle profile->我需要使用doFirst在这种情况下?您的
task initdb { println 'database' }
task profile(dependsOn: initdb) << { println 'profile' }
task initdb{println'数据库}
任务配置文件(dependsOn:initdb)此行为的原因是initdb
未正确声明。它缺少一个我想在profile
之前执行initdb
任务代码,但是通过调用gradle profile
->我需要使用doFirst
在这种情况下?您的第一个代码片段已经完成了这项任务,只是缺少了一个oh。我懂了。因此,每个任务都需要任务不是在配置时运行,而是在配置时配置。没有任务操作的任务在执行时不会执行任何操作。(声明任务类型的任务(例如,任务编译(类型:JavaCompile)
)从任务类型获取任务操作。)
task initdb { println 'database' }
task profile() << { println 'profile' }
task profile {
// code in here is about *configuring* the task;
// it *always* gets run (unless `--configuration-on-demand` is used)
dependsOn initdb
doLast { // adds a so-called "task action"
// code in here is about *executing* the task;
// it only gets run if and when Gradle decides to execute the task
println "profile"
}
}