anatoli anatoli - 8 months ago 138
Android Question

gradle dependency property with module exclude

i try to write central dependency file for my multi-module project.

ext {
supportVersion = '25.4.0'
junitVersion = '4.12'

supportDependencies = [
design: "com.android.support:design:${supportVersion}",
fragment: "com.android.support:support-fragment:${supportVersion}",
recyclerView: "com.android.support:recyclerview-v7:${supportVersion}"
]
...
}


to use them in modules

compile supportDependencies.design
compile supportDependencies.fragment
compile supportDependencies.recyclerView


but some dependencies have
exclude
to be compiled

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})


when i try to write property how

testingDependencies = [
espresso: ('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
]


i receive compile time syntaxis errors

Is it possible to create library-property with exclude in extensions to be compiled in module?

Answer Source

have solved my problem by adding in central dependency file

ext {   
   espressoVersion = '3.0.1'

   testingDependencies = [
        espresso: "com.android.support.test.espresso:espresso-core:${espressoVersion}"
   ]
}

and in module

androidTestCompile(testingDependencies.espresso, {
    exclude group: 'com.android.support', module: 'support-annotations'
})

so i have still one file with used dependency versions and can simple update versions in all modules

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download