Reputation: 7394
I am trying to refactor the way that I declare my dependencies in my project.
I am currently using the method described in this answer.
For example:
In top level build.gradle
I am defining my dependency as a constant as so:
ext.libraries = [
junit: 'junit:junit:4.10'
]
Then referencing it in the sub-module build.gradle
like so:
testCompile([
libraries.junit
])
Is the only advantage of doing this that it saves memory?
My current understanding is that by defining a dependency in the typical Gradle way in the top level build.gradle
, it is then added to EVERY sub-module.
But by defining it as a property and only referencing the property in the sub-modules that use it, you are saving memory as it is only added to the sub-modules that need it?
Am I correct?
Upvotes: 0
Views: 193
Reputation: 152837
You can't really add dependencies in the top-level gradle file.
Declaring dependencies like this is to avoid repetition. Avoiding repetition is good when you need to change something such as the version number of your dependencies: you'll need to edit only one place for that instead of all your submodule build.gradle files.
Upvotes: 1