alexfu
11/30/2017 - 4:03 PM

Grouping shared dependencies

Grouping shared dependencies

/**
 * This file would be located under /path/to/project/shared_dependencies.gradle
 */
 
def dependencyGroup(Closure closure) {
    closure.delegate = dependencies
    return closure
}

ext.sharedDependencies = [
        network: dependencyGroup {
            implementation "com.squareup.retrofit2:retrofit:2.3.0"
        }
]
/**
 * This file would be located under /path/to/project/mylib/build.gradle
 */
 
apply plugin: 'com.android.library'

android {
    // Usual stuff
}

apply from: "$project.rootDir/shared_dependencies.gradle"

dependencies {
    implementation 'com.android.support:appcompat-v7:26.1.0'
    sharedDependencies.network()
}
/**
 * This file would be located under /path/to/project/app/build.gradle
 */

apply plugin: 'com.android.application'

android {
    // Usual stuff
}

apply from: "$project.rootDir/shared_dependencies.gradle"

dependencies {
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    sharedDependencies.network()
}