从根到子项目导入脚本摇篮 [英] Import a Gradle script from the root into subprojects
问题描述
我想要做一个从适用:./gradle/script/common.gradle在我的根的build.gradle并将它提供给我所有的子项目。
I want to do an 'apply from: ./gradle/script/common.gradle' in my root build.gradle and have it be available to all of my subprojects.
我试图把在子项目的申请,但由于路径相对于它不会总是解析,(子项目并不平坦)。我也把它子项目之外在根但随后的目标不会被子项目解决。
I've tried putting the apply in the 'subprojects' but because the path is relative it won't always resolve, (the subprojects are not flat). I've also put it outside of the subprojects at the root but then the targets aren't resolved by the subprojects.
我一直没能找到一种方式来获得的工作目录在某种程度上从申请:'喜欢,或者如何让原来剧本的gradle正在执行从根目录或目录
I haven't been able to find a way to get the working directory in a way the 'apply from:' likes, or how to get the root directory or directory that the original gradle script is being executed from.
推荐答案
在你的根的build.gradle
:
allprojects { // or: subprojects { ... }
apply from: "gradle/script/common.gradle"
}
如果您需要这样的脚本的绝对路径,你总是可以做$ rootProject.projectDir / gradle这个/脚本/ common.gradle
。
这篇关于从根到子项目导入脚本摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!