Skip to content

Instantly share code, notes, and snippets.

@arunkumar9t2
Created February 27, 2020 14:06
Show Gist options
  • Save arunkumar9t2/5ed548ef4f838fb191b74ef29d1603f8 to your computer and use it in GitHub Desktop.
Save arunkumar9t2/5ed548ef4f838fb191b74ef29d1603f8 to your computer and use it in GitHub Desktop.
A gradle task that blocks Android builds started from IDE and copies the command to clipboard to quickly start build from terminal. Works only on Max
def validateIdeBuilds = tasks.register("validateIdeBuilds") {
doLast {
if (project.hasProperty("android.injected.invoked.from.ide")) {
def buildCommand = "./gradlew " + gradle.startParameter.taskNames.join(" ")
exec {
commandLine("sh", "-c", "echo \"$buildCommand\" | pbcopy")
}
throw new RuntimeException(
"Please avoid building from IDE and use commandLine instead." +
"The command has been copied to your clipboard"
)
}
}
}
tasks.named("preBuild").configure {
dependsOn validateIdeBuilds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment