【发布时间】:2015-09-02 01:12:30
【问题描述】:
这是我的:
build.gradle
task makeDirectoryStructure(type:Exec){
description 'Creates directory structure .'
commandLine 'mkdir'
args '-p' ,'top_dir/sub_dir_1/sub_dir_2'
println "This line is printed in configuration phase."
}
现在,由于我没有使用 '' 或 doFirst/doLast',我希望 mkdir 会被执行在配置阶段,即每当编译构建脚本时。例如如果我这样做了
$gradle tasks
我希望 mkdir 在配置阶段运行,即我的目录结构应该形成但没有发生。
但是我得到了这个输出:
yogeshwardancharan@yogeshwardancharan-Lenovo-G570:~/android_learning_resources/gradle_resources/ud867/1.01-Exercise-RunYourFirstTask$ gradle tasks
This line is printed in configuration phase.
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project '1.01-Exercise-RunYourFirstTask'. [incubating]
dependencies - Displays all dependencies declared in root project '1.01-Exercise-RunYourFirstTask'.
dependencyInsight - Displays the insight into a specific dependency in root project '1.01-Exercise-RunYourFirstTask'.
help - Displays a help message.
model - Displays the configuration model of root project '1.01-Exercise-RunYourFirstTask'. [incubating]
projects - Displays the sub-projects of root project '1.01-Exercise-RunYourFirstTask'.
properties - Displays the properties of root project '1.01-Exercise-RunYourFirstTask'.
tasks - Displays the tasks runnable from root project '1.01-Exercise-RunYourFirstTask'.
Other tasks
-----------
makeDirectoryStructure - Creates directory structure .
现在,在这一行的输出打印中
此行在配置阶段打印。
确认任务确实在配置阶段得到处理。
而且,当我发出命令时
$gradle makeDirectoryStructure
上面两行都打印出来了,目录结构也形成了。
所以,最后的问题是为什么我的 mkdir 没有在配置阶段运行,或者我是一些非常常见的概念。
【问题讨论】:
-
我从这里了解到:discuss.gradle.org/t/… 是 Exec 任务仅在配置阶段配置,它们的实际执行发生在执行阶段本身。