Defining dependencies for multiple options

Say we have four types of builds: debug, qa, beta, and release.

We can define dependencies for specific options:

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 variations 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 will indicate that the library is included for building debug and qa .

I believe the solution is to define a new Gradle configuration, but if I create an internalCompile configuration, I am not sure how to ensure that these dependencies are only compiled for qa and debug assemblies.

+5
source share
1 answer

extendsFrom

The names of the configurations from which this configuration is distributed. Superconfiguration artifacts 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' } 

As an alternative:

You can create a collection of artifact descriptors and use it with several 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 } 
+5
source

Source: https://habr.com/ru/post/1241062/


All Articles