为什么0000在gradle foo
之后不退出?删除doFirst
foo.doFirst{ delete '0000' }
后,0000就在那里。
doFirst
。
文档说:
Task doFirst(Closure action)
Adds the given closure to the beginning of this task's action list. The closure is passed this task as a parameter when executed.
完整命令日志:
isaac-mbp:swap isaac$ cat build.gradle
task foo {
mkdir '0000/a'
mkdir '0000/b'
}
foo.doFirst{ delete '0000' }
isaac-mbp:swap isaac$ gradle foo
:foo
BUILD SUCCESSFUL
Total time: 0.581 secs
isaac-mbp:swap isaac$ ls -lha 0000
ls: cannot access 0000: No such file or directory
isaac-mbp:swap isaac$ gradle -v
------------------------------------------------------------
Gradle 2.14
------------------------------------------------------------
Build time: 2016-06-14 07:16:37 UTC
Revision: cba5fea19f1e0c6a00cc904828a6ec4e11739abc
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_25 (Oracle Corporation 25.25-b02)
OS: Mac OS X 10.11.5 x86_64
答案 0 :(得分:2)
没有。
build.gradle
分两个阶段运行:配置和执行。以下代码中的逻辑(mkdir
s)将被执行每个时间build.gradle
被评估,因为它已添加到配置中时间:
task foo {
mkdir '0000/a'
mkdir '0000/b'
}
要解决此问题 - 添加操作:
task foo << {
mkdir '0000/a'
mkdir '0000/b'
}
现在doFirst
:
task foo << {
mkdir '0000/a'
mkdir '0000/b'
}
foo.doFirst { delete '0000' }
现在该任务有两个操作:mkdirs
和delete
,它们将以适当的顺序执行。请查看here