我目前的配置任务依赖于我从命令行调用的执行任务,即
$scope.addTask = function(index){
$scope.milestones.tasks.push({
taskSubject: $scope.index.formTaskSubject,
category: $scope.index.formCategory,
dueDate: $scope.index.formDate,
repeat: $scope.index.formRepeat,
assignee: $scope.index.formAssignee,
estHours: $scope.index.formEstTime
})
};
这个任务本质上应该抓取我在 assembleForTest 中组装的文件,然后部署它们(ssh等)
我的 assembleForTest 代码:
task deployTest(dependsOn: [build, assembleForTest]) << {
...
}
但问题是:我的项目是在此配置任务 assembleForTest 运行后构建的。即,它将在程序集完成后尝试构建,这意味着尝试进行过时(或不存在)部署。
Gradle有一些我见过的最糟糕的文档,我已经使用了一段时间,我仍然不理解理想的设置。
答案 0 :(得分:1)
这不会解决你的问题吗?
task assembleForTest(type: Sync, dependsOn: build) {
/* configuration phase, evaluated always and before execution phase of any task */
...
}
task deployTest(dependsOn: assembleForTest) << {
/* execution phase, evaluated only if the task is invoked and after configuration phase for all tasks has been finished */
...
}
编辑:我在示例中添加了评论。请注意,第一个任务提供配置,而第二个任务提供操作。开关由左移操作员完成。替代语法,特别有助于结合两个阶段定义,如下所示:
task plop() {
// some configuration
...
doLast {
// some action
...
}
}
如果你将println
放在'某些配置'的位置,它将始终打印,无论调用什么任务,都会在配置阶段进行评估。