lawonga lawonga - 1 year ago 96
Groovy Question

Gradle Crittercism on-build mapping upload not working

I'm trying to upload to Crittercism on build, and I put this at the bottom of my gradle file. However, it doesn't seem to be working when I build debug. What am I doing wrong?

task uploadMappingToProd() << {
def critterAppId = "abcde"
def appVersionName = "1.0.1"
def appVersionCode = "DEBUG"
def critterKey = "12345"

commandLine 'curl',
'-F', 'proguard=@build/outputs/mapping/production/release/mapping.txt',
'-F', "app_version=$appVersionName-$appVersionCode",
'-F', "key=$critterKey"

type Exec
dependsOn 'assembleDebug'

Answer Source

The way you've done it, the task that you have defined, uploadMappingToProd, will if invoked by some reason also invoke assembleDebug. Because you have asked uploadMappingToProd to depend on assembleDebug - not the reverse. Therefore assembleDebug will happily finish without getting anywhere close to uploadMappingToProd.

If you want the reverse dependency i.e. assembleDebug to depend on uploadMappingToProd then you need to add this line after defining your task.

afterEvaluate {       
    tasks.assembleDebug.dependsOn uploadMappingToProd

This will guarantee uploadMappingToProd is invoked everytime and before assembleDebug is invoked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download