Gradle-play-publisher: Missing serviceAccountCredentials should only impact publish tasks

Created on 5 Aug 2019  路  3Comments  路  Source: Triple-T/gradle-play-publisher

Describe the bug

Adding the plugin and not applying apply play.serviceAccountCredentials seems to break all gradle tasks. I expected only tasks related to the plugin to fail.

How To Reproduce

First, I have to explain something about my project setups: I want to make sure that potential contributors can "just clone and build". To achieve this, all secrets (API keys etc.) are located in gradle files outside the project folder and included depending on project properties. See below for my approach applied to the gradle-play-publisher

// complete file at https://github.com/ironjan/metal-only/blob/75d061b4456619614091a6630991fe7f41153a4a/rewrite/app/build.gradle
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'com.github.triplet.play' version '2.3.0'
}

if (project.hasProperty("metalonly.publishkey")) {
   // gradle.properties includes the setting  metalonly.publishkey=/some/external/path/metalonly_serviceaccount.json
    play {
        serviceAccountCredentials = file(project.property("metalonly.publishkey"))
    }
    println("Added publish key for gradle-play-publish")
}
else
{
    println("No publishkey setting found.") 
    // default case for other people. serviceAccountCredentials is not set.
}

Problem description

Adding the plugin without completing the setup seems to cause all tasks to fail. I only verified the behavior for the tasks tasks, buildRelease, and check. Since this was quite surprising, I submitted this issue as a bug.

[ljan@mobijaro rewrite]$ ./gradlew tasks

> Configure project :app
No publishkey setting found.
Applied production signing config

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > java.lang.IllegalStateException: No credentials specified. Please read our docs for more details: https://github.com/Triple-T/gradle-play-publisher#authenticating-gradle-play-publisher
   > KotlinJvmAndroidCompilation with name 'release' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Potential solutions/workarounds

The only workaround that comes to mind is adding some bogus credentials to the repository. This could complicate debugging potential issues later: when publishing fails...

  • did I forget to add the metalonly.publishkey setting?
  • did I forget to add my json to the appropriate place?
  • did my service account get terminated?
  • did the bogus credentials applied?

https://github.com/Triple-T/gradle-play-publisher/blob/753b1814d915f604ddd528de51fc23219d654198/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt#L137

val creds = checkNotNull(config.serviceAccountCredentials) {
                    "No credentials specified. Please read our docs for more details: " +
                            "https://github.com/Triple-T/gradle-play-publisher" +
                            "#authenticating-gradle-play-publisher"
                }

Instead of validating credentials at configuration time, the validation could be moved to the actual task implementation. That way, the configuration stage will not be impacted by an intended incomplete configuration. On the other hand, the publish tasks itself may fail.

Versions

The provided snippet to retrieve all version information fails with the aforementioned error when the plugin is not setup correctly.

  • Gradle Play Publisher: 2.3.0
  • Gradle Wrapper: 5.5.1
  • Android Gradle Plugin: 3.5.0-beta05

Expected behavior

Only publish tasks should fail when the credentials are missing. All other tasks should run the same as without the plugin.

Summary

Currently, the plugin causes all gradle tasks to fail when serviceAccountCredentials is not configured. If the plugin handles missing credentials when executing tasks instead of configuration time, above "optional application of credentials" may work as a way to

  • Prevent failing CI builds because of missing configuration as discussed in #460, #461 (CI builds most likely won't execute publish)
  • Have failing publish tasks for missing creds as mentioned in #549

Also note #555 in which configuration time validation was re-introduced.

bug

Most helpful comment

Thanks, I missed the corresponding part in the README. Here's a link in case someone else stumbles on this issue: https://github.com/Triple-T/gradle-play-publisher/#disabling-publishing ;)

All 3 comments

Thanks for the extensive issue description, but this is intended behavior. Just do this:

play {
    if (project.hasProperty("metalonly.publishkey")) {
        serviceAccountCredentials = file(project.property("metalonly.publishkey"))
    } else {
        isEnabled = false
    }
}

Please let me know if that doesn't fit your use case somehow.

Thanks, I missed the corresponding part in the README. Here's a link in case someone else stumbles on this issue: https://github.com/Triple-T/gradle-play-publisher/#disabling-publishing ;)

Yup, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivoberger picture ivoberger  路  4Comments

emartynov picture emartynov  路  4Comments

dannyroa picture dannyroa  路  5Comments

daniele-pecora picture daniele-pecora  路  5Comments

mhgk picture mhgk  路  3Comments