[英]gradle sharing properties among different projects which not related
I am having a file common.gradle which has common properties 我有一个common.gradle文件,它有共同的属性
def custom = [
status: 'SNAPSHOT',
group: 'com.custom.proj',
version: [
core: '1.2.0.0',
modle: '1.2.0.0',
base: '1.2.0.0'
]
]
and using it in build.gradle 并在build.gradle中使用它
apply from: 'file:///E:/gradle/common.gradle'
task props << {
println "group" + custom.group
}
and when i run gradle props getting below error 当我运行gradle道具低于错误
What went wrong: Execution failed for task ':props'.
出了什么问题:任务':props'的执行失败了。 Could not find property 'custom' on task ':props'.
无法在任务':props'上找到属性'custom'。
Try: Run with --stacktrace option to get the stack trace.
尝试:使用--stacktrace选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.
使用--info或--debug选项运行以获取更多日志输出。
def custom =
declares a local variable, which won't be visible outside commons.gradle
. def custom =
声明一个局部变量,它在commons.gradle
之外是不可见的。 Instead, you can declare an extra property on the Project
object: 相反,您可以在
Project
对象上声明一个额外的属性 :
ext.custom = ... // shorthand for `project.ext.custom = ...`
The usage will remain the same (eg custom.group
, not ext.custom.group
). 用法将保持不变(例如
custom.group
, 而不是 ext.custom.group
)。
If you want to share custom
among all build scripts in the same (multi-project) build, it's good enough to apply commons.gradle
to the root project, as project properties are inherited from parent to child projects. 如果要在同一(多项目)构建中的所有构建脚本之间共享
custom
,那么将commons.gradle
应用于根项目就足够了,因为项目属性是从父项目继承到子项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.