Say we have four build types: debug, qa, beta, and release.
We can define dependencies for specific variants like so:
dependencies {
// These dependencies are only included for debug and qa builds
debugCompile 'com.example:lib:1.0.0'
qaCompile 'com.example:lib:1.0.0'
}
Is there a way to compile these dependencies for multiple variants without repeating the artifact descriptor?
For example, I would like to do something like this:
dependencies {
internalCompile 'com.example:lib:1.0.0'
}
Where internalCompile
would specify that the library is included for both debug
and qa
builds.
I believe that the solution lies within defining a new Gradle configuration, but if I create an internalCompile
configuration I am unsure how to ensure that those dependencies are only compiled for qa
and debug
builds.
To define a flavor specific dependency you can use proCompile instead of compile in your dependency section. When you run gradle properties you get an overview of automatic created configurations.
A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant. In your case, you must define one flavorDimension named "type" and another dimension named "organization".
missingDimensionStrategy(dimension: String, requestedValue: String) Specifies a flavor that the plugin should try to use from a given dimension in a dependency.
A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.
extendsFrom
The names of the configurations which this configuration extends from. The artifacts of the super configurations are also available in this configuration.
configurations {
// debugCompile and qaCompile are already created by the Android Plugin
internalCompile
}
debugCompile.extendsFrom(internalCompile)
qaCompile.extendsFrom(internalCompile)
dependencies {
//this adds lib to both debugCompile and qaCompile
internalCompile 'com.example:lib:1.0.0'
}
You can create a collection of artifact descriptors and use it with multiple configurations.
List internalCompile = ["com.example:lib:1.0.0",
"commons-cli:commons-cli:1.0@jar",
"org.apache.ant:ant:1.9.4@jar"]
List somethingElse = ['org.hibernate:hibernate:3.0.5@jar',
'somegroup:someorg:1.0@jar']
dependencies {
debugCompile internalCompile
qaCompile internalCompile, somethingElse
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With