Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android/Gradle: conditionally apply plugin based on build type

I would like to make something like (pseudo code):

if (BuildType == "release"){
    apply plugin: 'testfairy'
} else if (BuildType == "debug"){
    apply plugin: 'io.fabric'
}

The idea is that based on the build type, apply (or not) a plugin. How to do it ?

like image 348
JoseF Avatar asked Mar 16 '16 15:03

JoseF


2 Answers

With Gradle 4.6, the following works:

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Release")) {
    apply plugin: 'testfairy'
} else if (getGradle().getStartParameter().getTaskRequests().toString().contains("Debug")) {
    apply plugin: 'io.fabric'
}
like image 139
Jason Grife Avatar answered Oct 02 '22 23:10

Jason Grife


Based on Stefan Oehme, a Gradle core developer, he said:

Plugins can't be applied to only "part of your project". They are either applied or not. What is the use case where this becomes a problem for you?

So, the answer is this is not possible. I have exposed my use cases where this is becomes a problem and I'll see what hi says about it.

like image 26
JoseF Avatar answered Oct 02 '22 23:10

JoseF