From ff8a8a0382f48f250aa13f9f3c6c126a6128c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Irland?= Date: Fri, 17 Jan 2020 15:52:34 -0300 Subject: [PATCH] Upgrade Google Play Publisher dependency (#53) --- CHANGELOG.md | 8 +++++ build.gradle.kts | 4 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../SnapshotPublisherPlugin.kt | 3 +- .../plugin/PlayPublisherPluginHelper.kt | 30 ++++++++----------- .../snapshotpublisher/task/ErrorTask.kt | 2 ++ .../task/PrepareGooglePlayReleaseTask.kt | 9 +++--- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3fd90..7d04770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Change Log ========== All notable changes to this project will be documented in this file. +[Version 2.1.0 _(TBD)_](https://github.com/xmartlabs/android-snapshot-publisher/releases/tag/v2.1.0) +--- + +### Changes +- Upgrade Google Play Publisher dependency to [v2.6.2](https://github.com/Triple-T/gradle-play-publisher/releases/tag/2.6.2). +- Change min required gradle version to 6.0. + + [Version 2.0.0 _(2019-10-15)_](https://github.com/xmartlabs/android-snapshot-publisher/releases/tag/v2.0.0) --- diff --git a/build.gradle.kts b/build.gradle.kts index a1b6f3f..e99b4c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.0.0-RC12") - implementation("com.github.triplet.gradle:play-publisher:2.4.1") + implementation("com.github.triplet.gradle:play-publisher:2.6.2") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev46-1.25.0") implementation("com.google.firebase:firebase-appdistribution-gradle:1.0.0") @@ -47,7 +47,7 @@ jacoco { } group = "com.xmartlabs" -version = "2.0.0" +version = "2.1.0" gradlePlugin { plugins { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca9d628..1ba7206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/xmartlabs/snapshotpublisher/SnapshotPublisherPlugin.kt b/src/main/kotlin/com/xmartlabs/snapshotpublisher/SnapshotPublisherPlugin.kt index 2197d8f..42adaf1 100644 --- a/src/main/kotlin/com/xmartlabs/snapshotpublisher/SnapshotPublisherPlugin.kt +++ b/src/main/kotlin/com/xmartlabs/snapshotpublisher/SnapshotPublisherPlugin.kt @@ -1,7 +1,6 @@ package com.xmartlabs.snapshotpublisher import com.android.build.gradle.api.ApplicationVariant -import com.github.triplet.gradle.play.tasks.internal.PublishArtifactTaskBase import com.xmartlabs.snapshotpublisher.model.FirebaseAppDistributionReleaseConfig import com.xmartlabs.snapshotpublisher.model.GooglePlayConfig import com.xmartlabs.snapshotpublisher.model.SnapshotReleaseExtension @@ -119,7 +118,7 @@ class SnapshotPublisherPlugin : Plugin { val googlePlayConfig = project.snapshotReleaseExtension.googlePlay if (ErrorHelper.isServiceAccountCredentialFileValid(project, googlePlayConfig.serviceAccountCredentials)) { - val publishGooglePlayTask: PublishArtifactTaskBase = if (googlePlayConfig.defaultToAppBundles) { + val publishGooglePlayTask: Task = if (googlePlayConfig.defaultToAppBundles) { PlayPublisherPluginHelper.getPublishBundleTask(this, variant) } else { PlayPublisherPluginHelper.getPublishApkTask(this, variant) diff --git a/src/main/kotlin/com/xmartlabs/snapshotpublisher/plugin/PlayPublisherPluginHelper.kt b/src/main/kotlin/com/xmartlabs/snapshotpublisher/plugin/PlayPublisherPluginHelper.kt index 9a8b7d8..5291f67 100644 --- a/src/main/kotlin/com/xmartlabs/snapshotpublisher/plugin/PlayPublisherPluginHelper.kt +++ b/src/main/kotlin/com/xmartlabs/snapshotpublisher/plugin/PlayPublisherPluginHelper.kt @@ -4,9 +4,6 @@ import com.android.build.gradle.api.ApplicationVariant import com.android.build.gradle.api.BaseVariant import com.android.builder.model.Version import com.github.triplet.gradle.play.PlayPublisherExtension -import com.github.triplet.gradle.play.PlayPublisherPlugin -import com.github.triplet.gradle.play.tasks.PublishApk -import com.github.triplet.gradle.play.tasks.PublishBundle import com.xmartlabs.snapshotpublisher.model.SnapshotReleaseExtension import com.xmartlabs.snapshotpublisher.utils.ErrorHelper import com.xmartlabs.snapshotpublisher.utils.snapshotReleaseExtension @@ -18,12 +15,13 @@ import java.io.File internal object PlayPublisherPluginHelper { private const val PLAY_EXTENSION_NAME = "play" - private val MIN_GRADLE_VERSION = GradleVersion.version("5.6.1") + private val MIN_GRADLE_VERSION = GradleVersion.version("6.0") private val MIN_AGP_VERSION = VersionNumber.parse("3.5.0") private const val GENERATE_RESOURCES_TASK_NAME = "generate%sPlayResources" private const val PUBLISH_APK_TASK_NAME = "publish%sApk" private const val PUBLISH_BUNDLE_TASK_NAME = "publish%sBundle" + private const val PLAY_PUBLISHER_PLUGIN_CLASS = "com.github.triplet.gradle.play.PlayPublisherPlugin" // https://github.com/Triple-T/gradle-play-publisher/blob/3e86503431794792dc63dd6b5bb51e03493f1ed7/plugin/src/main/kotlin/com/github/triplet/gradle/play/internal/Constants.kt private const val RESOURCE_PATH = "res" @@ -31,14 +29,9 @@ internal object PlayPublisherPluginHelper { private const val RESOURCES_OUTPUT_PATH = "generated/$OUTPUT_PATH" private const val RELEASE_NOTES_PATH = "release-notes" - // https://github.com/Triple-T/gradle-play-publisher/blob/4d3f98128c8c86bc1ea37fd34d8f4b16dbf93d1b/plugin/src/main/kotlin/com/github/triplet/gradle/play/internal/Validation.kt#L28 private fun PlayPublisherExtension.areCredsValid(): Boolean { val creds = serviceAccountCredentials ?: return false - return if (creds.extension.equals("json", true)) { - serviceAccountEmail == null - } else { - serviceAccountEmail != null - } + return creds.extension.equals("json", true) } private val BaseVariant.playPath get() = "$RESOURCES_OUTPUT_PATH/$name" @@ -52,16 +45,17 @@ internal object PlayPublisherPluginHelper { private val Project.playPublisherExtension get() = project.extensions.findByName(PLAY_EXTENSION_NAME) as PlayPublisherExtension - @Suppress("UnsafeCast") - fun getPublishBundleTask(project: Project, variant: ApplicationVariant): PublishBundle = - project.tasks.getByName(PUBLISH_BUNDLE_TASK_NAME.format(variant.capitalizedName)) as PublishBundle + private fun Project.getTask(variant: ApplicationVariant, taskName: String): Task = + project.tasks.getByName(taskName.format(variant.capitalizedName)) - @Suppress("UnsafeCast") - fun getPublishApkTask(project: Project, variant: ApplicationVariant): PublishApk = - project.tasks.getByName(PUBLISH_APK_TASK_NAME.format(variant.capitalizedName)) as PublishApk + fun getPublishBundleTask(project: Project, variant: ApplicationVariant): Task = + project.getTask(variant, PUBLISH_BUNDLE_TASK_NAME) + + fun getPublishApkTask(project: Project, variant: ApplicationVariant): Task = + project.getTask(variant, PUBLISH_APK_TASK_NAME) fun getGenerateResourcesTask(project: Project, variant: ApplicationVariant): Task = - project.tasks.getByName(GENERATE_RESOURCES_TASK_NAME.format(variant.capitalizedName)) + project.getTask(variant, GENERATE_RESOURCES_TASK_NAME) // Required in https://github.com/Triple-T/gradle-play-publisher/blob/40092f24d68034395c4c3399dbef0c5eb2f2c484/common/validation/src/main/kotlin/com/github/triplet/gradle/common/validation/Validation.kt#L9 private fun checkGradleVersion() { @@ -104,7 +98,7 @@ internal object PlayPublisherPluginHelper { } } @Suppress("UnstableApiUsage") - project.pluginManager.apply(PlayPublisherPlugin::class.java) + project.pluginManager.apply(Class.forName(PLAY_PUBLISHER_PLUGIN_CLASS)) } private fun setupPluginCredentials(project: Project, releaseSetup: SnapshotReleaseExtension) { diff --git a/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/ErrorTask.kt b/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/ErrorTask.kt index 6137ad8..0ec62ec 100644 --- a/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/ErrorTask.kt +++ b/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/ErrorTask.kt @@ -1,9 +1,11 @@ package com.xmartlabs.snapshotpublisher.task import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction open class ErrorTask : DefaultTask() { + @Input lateinit var message: String @Suppress("unused") diff --git a/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/PrepareGooglePlayReleaseTask.kt b/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/PrepareGooglePlayReleaseTask.kt index 9c27d96..0500572 100644 --- a/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/PrepareGooglePlayReleaseTask.kt +++ b/src/main/kotlin/com/xmartlabs/snapshotpublisher/task/PrepareGooglePlayReleaseTask.kt @@ -1,15 +1,17 @@ package com.xmartlabs.snapshotpublisher.task import com.android.build.gradle.api.ApplicationVariant -import com.github.triplet.gradle.play.tasks.internal.PublishArtifactTaskBase +import com.github.triplet.gradle.play.PlayPublisherExtension import com.xmartlabs.snapshotpublisher.Constants import com.xmartlabs.snapshotpublisher.plugin.PlayPublisherPluginHelper import com.xmartlabs.snapshotpublisher.utils.AndroidPublisherHelper import com.xmartlabs.snapshotpublisher.utils.ReleaseNotesGenerator import com.xmartlabs.snapshotpublisher.utils.snapshotReleaseExtension import org.gradle.api.DefaultTask +import org.gradle.api.Task import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction +import org.gradle.kotlin.dsl.getByType import java.io.File open class PrepareGooglePlayReleaseTask : DefaultTask() { @@ -18,7 +20,7 @@ open class PrepareGooglePlayReleaseTask : DefaultTask() { } @get:Internal - internal lateinit var publishGooglePlayTask: PublishArtifactTaskBase + internal lateinit var publishGooglePlayTask: Task @get:Internal internal lateinit var variant: ApplicationVariant @@ -30,8 +32,7 @@ open class PrepareGooglePlayReleaseTask : DefaultTask() { @TaskAction fun action() { createReleaseNotesFile() - - with(publishGooglePlayTask.extension) { + with(project.extensions.getByType()) { defaultToAppBundles = googlePlayConfig.defaultToAppBundles releaseStatus = googlePlayConfig.releaseStatus resolutionStrategy = googlePlayConfig.resolutionStrategy