我试图编写自己的Gradle任务:
task(incVersion) << {
[...]
}
task cleanDocBuild(dependsOn: ['clean','cleanDoc','incVersion','asciidoctor','war']) << {
cleanDoc.dependsOn clean
incVersion.dependsOn cleanDoc
asciidoctor.dependsOn incVersion
war.dependsOn asciidoctor
println 'Start Building...'
}
task(cleanDoc) << {
[...]
}
asciidoctor {
[...]
}
我想按特定顺序调用任务:
我怎样才能做到这一点?
最佳答案
您不仅需要根据任务设置dependsOn
属性(此属性不进行任何排序,仅提供任务依赖项),还需要根据需要设置mustRunAfter
或shouldRunAfter
,以使该任务按预定义的顺序运行。您可以在official user guide中了解它。您的情况可能类似于:
clenDoc.mustRunAfter clean
incVersion.mustRunAfter clenDoc
asciidoctor.mustRunAfter incVersion
war.mustRunAfter asciidoctor
cleanDocBuild.mustRunAfter war