Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

Credentials are validated at configuration time. #774

Closed blazsolar closed 4 years ago

blazsolar commented 4 years ago

Describe the bug

At the moment credentials are validated at the configuration phase of the project. Problem is that one may not want to have serviceAccountCredentials file accessible to everyone and will therefore not be set every time. For example, you don't want to have the file shared among the development team and just have it accessible on CI. Why is this validation not done when credentials actually need to be used?

How To Reproduce

Don't set play.serviceAccountCredentials property and run ./gradlew tasks. Tasks task has nothing to do with this plugin but it will still fail.

Versions

Expected behavior

The plugin should validate credentials when they are needed and not at configuration time.

Caused by: 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
        at com.github.triplet.gradle.play.internal.ValidationKt.validateCreds(Validation.kt:11)
        at com.github.triplet.gradle.play.PlayPublisherPlugin$applyInternal$1.execute(PlayPublisherPlugin.kt:141)
        at com.github.triplet.gradle.play.PlayPublisherPlugin$applyInternal$1.execute(PlayPublisherPlugin.kt:49)
        at org.gradle.internal.ImmutableActionSet$SetWithManyActions.execute(ImmutableActionSet.java:329)
        at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:264)
        at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:253)
        at com.android.build.gradle.AppExtension.addVariant(AppExtension.java:84)
        at com.android.build.gradle.internal.ApiObjectFactory.create(ApiObjectFactory.java:127)
        ... 146 more
blazsolar commented 4 years ago

Resolved it by reading documentation all the way through. 😄

claust commented 4 years ago

Resolved it by reading documentation all the way through. 😄

On our build server I use an environment variable ANDROID_PUBLISHER_CREDENTIALS, and therefore do not specify serviceAccountCredentials in the gradle file. But in this case all gradle tasks fails when run locally.

Can you be a bit more specific about how you fixed it?

----- EDIT ----- OK, I fixed this by enabling the publisher task using an environment variable only present on the build server.

play { enabled.set(System.getenv("CI") == "true") }

blazsolar commented 3 years ago

What i did was set

play {
    isEnabled = false
}

and then added also

android {
    playConfigs {
        register("<flavourName>") {
            isEnabled = project.hasProperty("<gradle_properties_key_for_play_credewntials>")
        }
    }
}

and since <gradle_properties_key_for_play_credewntials> is only set on CI, it works as expected.