Gradle:子模块中抛出类错误的属性? [英] Gradle: No such property for class error thrown in sub-module?

查看:283
本文介绍了Gradle:子模块中抛出类错误的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用依赖项这个答案的-grad-how-do-i-declare-common-dependencies-in-a-one-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

如何解决这个问题?

依赖性声明为顶级属性 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


推荐答案


  1. 在您的顶级 settings.gradle 中,包含您的子项目:

  1. 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.


    1. 要在您的子项目build.gradle中使用此选项,请执行以下操作:

    1. To use this in your subproject build.gradle:

    dependencies{
      testCompile libraries.junit 
    }
    


    这篇关于Gradle:子模块中抛出类错误的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆