Skip to content

Commit

Permalink
Clarify errors when AGP isn't available (#779)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
SUPERCILEX authored Feb 26, 2020
1 parent fcc0a40 commit a9a6bee
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.triplet.gradle.common.validation

import com.android.Version
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.util.GradleVersion
import org.gradle.util.VersionNumber

internal class RuntimeValidationPlugin : Plugin<Project> {
override fun apply(project: Project) {
check(project === project.rootProject)

val agpVersion = try {
VersionNumber.parse(Version.ANDROID_GRADLE_PLUGIN_VERSION)
} catch (e: NoClassDefFoundError) {
null
}
val validator = RuntimeValidator(
GradleVersion.current(), MIN_GRADLE_VERSION, agpVersion, MIN_AGP_VERSION)

validator.validate()
}

private companion object {
val MIN_GRADLE_VERSION = GradleVersion.version("6.2")
val MIN_AGP_VERSION = VersionNumber.parse("3.6.0")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class RuntimeValidator(
private val currentGradleVersion: GradleVersion,
private val minGradleVersion: GradleVersion,

private val currentAgpVersion: VersionNumber,
private val currentAgpVersion: VersionNumber?,
private val minAgpVersion: VersionNumber
) {
fun validate() {
Expand All @@ -27,11 +27,14 @@ internal class RuntimeValidator(
}

private fun validateAgp() {
check(currentAgpVersion >= minAgpVersion) {
check(null != currentAgpVersion && currentAgpVersion >= minAgpVersion) {
"""
|Gradle Play Publisher's minimum Android Gradle Plugin version is at least
|$minAgpVersion and yours is $currentAgpVersion. Find the latest version and upgrade
|$minAgpVersion and yours is ${currentAgpVersion ?: "unknown"}. Make sure you've applied
|the AGP alongside this plugin. Find the latest AGP version and upgrade
|instructions at https://developer.android.com/studio/releases/gradle-plugin.
|For GPP installation docs, see here:
|https://github.com/Triple-T/gradle-play-publisher#installation
""".trimMargin()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package com.github.triplet.gradle.common.validation

import com.android.Version
import com.android.build.gradle.api.ApplicationVariant
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.gradle.util.GradleVersion
import org.gradle.util.VersionNumber

private val MIN_GRADLE_VERSION = GradleVersion.version("6.2")
private val MIN_AGP_VERSION = VersionNumber.parse("3.6.0-rc03")
import org.gradle.kotlin.dsl.apply

/**
* Validates required dependencies. If GPP can't run in the current context, an error will be
* thrown.
*/
fun validateRuntime() {
val agpVersion = VersionNumber.parse(Version.ANDROID_GRADLE_PLUGIN_VERSION)
val validator = RuntimeValidator(
GradleVersion.current(), MIN_GRADLE_VERSION, agpVersion, MIN_AGP_VERSION)

validator.validate()
fun Project.validateRuntime() {
rootProject.plugins.apply(RuntimeValidationPlugin::class)
}

/** @return true if the variant is *not* debuggable and can therefore be published. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import kotlin.reflect.KMutableProperty1
@Suppress("unused") // Used by Gradle
internal class PlayPublisherPlugin : Plugin<Project> {
override fun apply(project: Project) {
validateRuntime()
project.validateRuntime()

project.extensions.create<PlayPublisherExtension>(PLAY_PATH)
project.plugins.withType<AppPlugin> {
Expand Down
2 changes: 1 addition & 1 deletion testapp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

dependencies {
classpath(kotlin("gradle-plugin", embeddedKotlinVersion))
classpath("com.android.tools.build:gradle:3.6.0-rc03")
classpath("com.android.tools.build:gradle:3.6.0")
classpath("com.github.triplet.gradle:play-publisher:" +
file("../version.txt").readText().trim())
}
Expand Down

0 comments on commit a9a6bee

Please sign in to comment.