Quantcast
Channel: Gubatron.com
Viewing all articles
Browse latest Browse all 174

gradle/groovy: A simple way to check if a gradle task name has been invoked (e.g. “assembleRelease” for Android developers)

$
0
0

If you google for this question, you’ll find a bunch of crap answers about creating tasks and checking the task graph, bullshit.

All you need to do is check if a parameter has been passed to gradle.

Keep it simple and stupid:

boolean isAssembleRelease = gradle.startParameter.taskNames.contains("assembleRelease")

(If you’re working with an android project, you can define that variable before the android { section starts)

Then, if you need to do something different somewhere else down in your script, say, ask for a key alias and key password to sign your release (because they invoked ./gradlew assembleRelease you do:

signingConfigs {
        release {
            if (isAssembleRelease) {
                // your code here to ask for the key alias and password
            }
}

Viewing all articles
Browse latest Browse all 174

Trending Articles