1

In my top level build.gradle project I am attempting to add extra properties using the following:

project.ext.libraries = [

        junit: 'junit:junit:4.10'

]

I then attempt to reference them in a lower level build.gradle but get this error:

testCompile([
                        project.libraries.junit
]) 

However I get this error:

"Could not find property "libraries" for project

Do I need to add anything else to my Gradle code to get this to work?

java123999
  • 6,974
  • 36
  • 77
  • 121
  • Is your `ext.libraries` declaration in the `allprojects` or `subprojects` section? – RaGe Dec 21 '15 at 15:16
  • 1
    Possible duplicate of [Gradle: No such property for class error thrown in sub-module?](http://stackoverflow.com/questions/34338826/gradle-no-such-property-for-class-error-thrown-in-sub-module) – RaGe Dec 21 '15 at 16:07

1 Answers1

1

Assuming that you have already setup the subproject relationship properly in root settings.gradle using include, in root level build.gradle

ext.libraries = [junit: 'junit:junit:4.10']

In your subproject:

dependencies{
  testCompile libraries.junit
}

All ext properties defined in your root project are available in the sub projects.

RaGe
  • 22,696
  • 11
  • 72
  • 104