Gradle: No such property for class error thrown in sub-module?(Gradle:子模块中抛出的类错误没有这样的属性?)
问题描述
我正在尝试使用 dependencies-i-declare-common-dependencies-in-a-single-place">这个答案.
I am trying to declare the dependencies in my gradle project using the technique described in this answer.
但是当我这样做时,我得到了这个错误:
However when I do so I get this error:
No such property: libraries for class
我该如何解决这个问题?
How can I fix this?
在顶级 build.gradle 中声明为属性的依赖项如下:
Dependencies declared as properties at top level build.gradle as follows:
ext.libraries = [
junit: 'junit:junit:4.10'
]
尝试在 模块级别 build.gradle 中检索依赖项(抛出错误):
Trying to retrieve dependency in module level build.gradle (where error is being thrown):
testCompile([
libraries.junit
])
抛出错误:
No such property: libraries for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
推荐答案
在您的顶级
settings.gradle中,包含您的子项目:
In your top level
settings.gradle, include your subproject:
include 'subproject'
在您的顶级 build.gradle 中定义您的 ext 属性:
In your top level build.gradle define your ext properties:
ext.libraries = [junit: 'junit:junit:4.10']
它不必是地图,如果您只使用 1 个值,但我坚持使用您的格式.
it does not have to be a map, if you're using just 1 value, but I'm sticking with your formatting.
要在你的
子项目 build.gradle中使用它:
dependencies{
testCompile libraries.junit
}
这篇关于Gradle:子模块中抛出的类错误没有这样的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Gradle:子模块中抛出的类错误没有这样的属性?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
