在我的顶级build.gradle
项目中,我尝试使用以下内容添加extra properties
:
project.ext.libraries = [
junit: 'junit:junit:4.10'
]
然后我尝试在较低级别build.gradle
中引用它们,但得到此错误:
testCompile([
project.libraries.junit
])
但是我收到了这个错误:
"Could not find property "libraries" for project
我是否需要在Gradle代码中添加其他内容才能使其正常工作?
答案 0 :(得分:1)
假设您已使用settings.gradle
在根include
中正确设置子项目关系,则在根级别build.gradle中
ext.libraries = [junit: 'junit:junit:4.10']
在您的子项目中:
dependencies{
testCompile libraries.junit
}
根项目中定义的所有ext属性都可在子项目中使用。