..
apply from: 'dependencies.gradle'
// <- enable this when building an .aar
// apply from: 'dependencies-test.gradle'
// <- enable this when testing
..
and I currently have to manually comment/uncomment the correct dependencies file in build.gradle depending on what I’m doing.
Is there a way to tell gradle to use one set of dependencies when running “gradlew connectedInstrumentTest” and a different set of dependencies when running “gradlew uploadArchives”?
Wouldn’t be possible to have an if statements to apply one file or another? A condition could be controlled by a property set from a command line or in case you would like to distinguish connectedInstrumentTest and uploadArchives by checking gradle.startParameter.taskNames.
if (gradle.startParameter.taskNames.contains("connectedInstrumentTest")) {
apply from: 'dependencies.gradle'
} else ...
A drawback of using this construction is that you have to use this tasks names explicit in a command line. It would be better to use:
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(developerBuild)) {
...
}
}
which also detects tasks in a situation they are required by some other tasks (e.g. “gradle check” requires a test task), but the task execution graph is created after the configuration phase which is too late in your case (or at least you would have to do some manual operations on dependencies - which should be possible, but is more complicated).