According to Gradle, the plugin version 3.0.0 is a more convenient way to do this. We can control whether each dependency is available only for the current module or for the current module and any modules that depend on it. This will allow us to easily share dependencies between modules within the project.
Here we used to declare dependencies:
- compile 'example.dependency: 1.0.0'
Here are the new configurations that should replace compilation:
- implementation . example.dependency: 1.0.0 '-> this dependency is used only in this module
- api 'example.dependency: 1.0.0' β this dependency will also be available in any assemblies that depend on this module.
Here's how to do this with the architecture that you talked about in the question. Assuming we have a module called 'library' that is consumed by the application module, we can use the api configuration to declare that the dependency should be shared with any module that depends on it.
build.gradle library module
dependencies { // dependencies marked 'implementation' will only be available to the current module implementation 'com.squareup.okhttp:okhttp:2.4.0' // any dependencies marked 'api' will also be available to app module api 'com.squareup.retrofit:retrofit:1.9.0' api 'io.reactivex:rxjava:1.0.13' api 'io.reactivex:rxandroid:0.25.0' }
build.gradle application module:
dependencies { // declare dependency on library module implementation project(':library') // only need to declare dependencies unique to app implementation 'example.dependency:1.0.0' }
Jules source share