What use instead of TaskInternal execute() at grad

2019-08-03 14:08发布

问题:

My custom task at gradle-4.10.1:

task fabricUploadApkDevelop(group: "fabric", dependsOn: ['assembleDevDebug']) {
    doLast {
        //fabric gradle task `assembleRelease crashlyticsUploadDistributionDevDevelop` and options:
        def task = tasks.getByName("crashlyticsUploadDistributionDevDebug")
        task.ext.betaDistributionGroupAliases = "develop"
        task.ext.betaDistributionNotifications = true
        task.ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
        task.execute()
    }
}

But at gradle-5.1.1:

TaskInternal.execute() is removed, so now I can't run my task.execute(), how to change my custom task? Or how to run task crashlyticsUploadDistributionDevDebug with params via terminal?

I tried to use:

  //gradle 5.x
task fabricUploadApkDevelop(group: "fabric") {
    ext.betaDistributionGroupAliases = "develop"
    ext.betaDistributionNotifications = true
    ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"

    doLast {
        ext.betaDistributionGroupAliases = "develop"
        ext.betaDistributionNotifications = true
        ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
    }

    finalizedBy 'crashlyticsUploadDistributionDevDebug'
}

But crashlyticsUploadDistributionDevDebug task doesn't get params...

回答1:

The sources for the Fabric/Crashlytics Gradle plugin don’t seem to be publicly available (and I have never used it myself), otherwise I would have checked there. But given your working example for Gradle 4 and looking at the issue through my vanilla Gradle glasses, I’d expect that the following should/could work with Gradle 5:

project.afterEvaluate {
    crashlyticsUploadDistributionDevDebug.doFirst {
        ext.betaDistributionGroupAliases = "develop"
        ext.betaDistributionNotifications = true
        ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
    }
}

task fabricUploadApkDevelop(group: "fabric") {
    dependsOn 'crashlyticsUploadDistributionDevDebug'
}

I’d even expect there to be a nicer way to do it but since I can’t test this myself, I wanted to play it safe. Let me know if it worked or what didn’t!