本文新建一个文件other.gradle, 内容如下:
println "configuring $project"
task hello {
doLast{
println 'hello from other script'
}
}
然后在主构建脚本build.gradle里引用这个外部脚本:
apply from: ‘other.gradle’
执行输出:
configuring root project ‘quickstart’
hello from other script
这个’quickstart’是哪里来的呢?other.gradle里使用占位符$project, 而本地文件夹里还有个文件settings.gradle, 里面定义了root project的名称:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":