Last active
August 10, 2016 10:01
-
-
Save olivierperez/ab0e7121a0dbacc9b124887faa9d9c21 to your computer and use it in GitHub Desktop.
Gradle tasks & scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A task to call from your CI | |
task ci_job { | |
group = 'ci' | |
} | |
if (project.hasProperty('buildVariant') && !project.property('buildVariant').isEmpty()) { | |
def testVariant = 'MockStubDebug' | |
def checkVariant = 'MockRegularDebug' | |
project.afterEvaluate { | |
/* Assemble */ | |
def assemble = tasks["assemble${buildVariant}"] | |
assemble.mustRunAfter clean | |
/* Unit test */ | |
def unitTests = project.tasks["test${testVariant}UnitTest"] | |
unitTests.mustRunAfter assemble | |
unitTests.onlyIf { | |
!project.hasProperty('skipUnitTest') || project.property('skipUnitTest') != 'true' | |
} | |
/* Quality */ | |
task quality | |
quality.dependsOn project.tasks["lint${checkVariant}"] | |
quality.dependsOn project.tasks["findbugs${checkVariant}"] | |
quality.dependsOn project.tasks["checkstyle"] | |
quality.onlyIf { | |
!project.hasProperty('skipQuality') || project.property('skipQuality') != 'true' | |
} | |
/* Upload to Crashlytics */ | |
def uploadCrashlytics = project.tasks.findByName("crashlyticsUploadDistribution${buildVariant}"); | |
if (uploadCrashlytics != null) { | |
uploadCrashlytics.mustRunAfter assemble, unitTests, quality | |
uploadCrashlytics.onlyIf { | |
project.hasProperty('uploadToCrashlytics') && project.property('uploadToCrashlytics') == 'true' | |
} | |
} | |
/* Execute all */ | |
ci_job.dependsOn clean | |
ci_job.dependsOn assemble | |
ci_job.dependsOn unitTests | |
ci_job.dependsOn quality | |
if (uploadCrashlytics != null) { | |
ci_job.dependsOn uploadCrashlytics | |
} | |
} | |
} else { | |
ci_job << { | |
println "Nothing to do, buildVariant is not wel defined" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use GCM with multi-flavors | |
gradle.taskGraph.beforeTask { Task task -> | |
if (task.name ==~ /process.*GoogleServices/) { | |
android.applicationVariants.all { variant -> | |
if (task.name ==~ /(?i)process${variant.name}GoogleServices/) { | |
def envFlavor = variant.productFlavors.get(0).name | |
copy { | |
from "./src/${envFlavor}" | |
into '.' | |
include 'google-services.json' | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The Gradle tasks & scripts I need everywhere. | |
- ci_job | |
- GCM with flavor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment