Skip to content

Instantly share code, notes, and snippets.

@mr-archano
Created February 26, 2018 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr-archano/6ec5ac4951de036a54c1be0750ae7577 to your computer and use it in GitHub Desktop.
Save mr-archano/6ec5ac4951de036a54c1be0750ae7577 to your computer and use it in GitHub Desktop.
Conditionally apply plugin
apply plugin: 'com.novoda.build-properties'
buildProperties {
local {
file rootProject.file('local.properties')
}
}
apply from: file('utilities.gradle')
maybeApply plugin: 'blah', when: buildProperties.local['applyBlah'].or(true)
ext.when = {
if (it instanceof com.novoda.buildproperties.Entry) {
return it.boolean
}
return it as Boolean
}
ext.maybeApply = { Map<String, ?> options ->
if (when(options.remove('when'))) {
logger.log(LogLevel.DEBUG, ">>> '$options.plugin' plugin applied...")
apply options
} else {
logger.log(LogLevel.WARN, ">>> \n/!\\ '$options.plugin' plugin not applied! /!\\\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment