Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to new, non-deprecated AGP APIs. Min AGP version now 8.0. #1092

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ moshix = "0.19.0"
okio = "2.10.0"
retrofit = "2.9.0"

agp = "7.4.2"
agp-common = "30.4.2"
agp = "8.0.2"
#agp = "8.1.4
#agp = "8.2.1"
#agp = "8.3.0-beta01" # Provides `Sources.manifests`
agp-common = "31.2.0"

[libraries]
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.gradle.BuildscriptBlock
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.utils.DebugAware

@SuppressWarnings('GrMethodMayBeStatic')
abstract class AbstractProject extends AbstractGradleProject {

protected static final PRINT_ADVICE = "dependency.analysis.print.build.health=true"
protected static final String PRINT_ADVICE = "dependency.analysis.print.build.health=true"

@Override
protected GradleProject.Builder newGradleProjectBuilder(GradleProject.DslKind dslKind = GradleProject.DslKind.GROOVY) {
protected GradleProject.Builder newGradleProjectBuilder(
GradleProject.DslKind dslKind = GradleProject.DslKind.GROOVY
) {
def additionalProperties = GradleProperties.of(PRINT_ADVICE)
// There is a Gradle bug that makes tests break when the test uses CC and we're also debugging
if (!DebugAware.debug) {
additionalProperties += GradleProperties.enableConfigurationCache()
}

return super.newGradleProjectBuilder(dslKind)
.withRootProject { r ->
r.gradleProperties += GradleProperties.enableConfigurationCache() + PRINT_ADVICE
r.gradleProperties += additionalProperties
r.withBuildScript { bs ->
bs.plugins(Plugins.dependencyAnalysis, Plugins.kotlinNoApply)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,36 @@ import com.autonomousapps.fixtures.ProjectDirProvider
import com.autonomousapps.internal.android.AgpVersion
import org.gradle.util.GradleVersion

/**
* @see <a href="https://maven.google.com/web/m_index.html?q=com.android.tools.build#com.android.tools.build:gradle">AGP artifacts</a>
*/
abstract class AbstractAndroidSpec extends AbstractFunctionalSpec {

protected ProjectDirProvider androidProject = null

protected static final AGP_7_3 = AgpVersion.version('7.3.1')
protected static final AGP_7_4 = AgpVersion.version('7.4.2')
protected static final AGP_8_0 = AgpVersion.version('8.0.2')
protected static final AGP_8_1 = AgpVersion.version('8.1.0')
protected static final AGP_8_2 = AgpVersion.version('8.2.0-alpha16')
protected static final AGP_8_1 = AgpVersion.version('8.1.4')
protected static final AGP_8_2 = AgpVersion.version('8.2.0')
protected static final AGP_8_3 = AgpVersion.version('8.3.0-beta01')
protected static final AGP_8_4 = AgpVersion.version('8.4.0-alpha01')

protected static final AGP_LATEST = AGP_8_2
protected static final AGP_LATEST = AGP_8_4

/**
* {@code AGP_7_4} represents the minimum stable _tested_ version. {@code AGP_8_1} represents the maximum stable
* TODO(tsr): this doc is perpetually out of date.
*
* {@code AGP_8_0} represents the minimum stable _tested_ version. {@code AGP_8_1} represents the maximum stable
* _tested_ version. We also test against the latest alpha, {@code AGP_8_2} at time of writing. DAGP may work with
* other versions of AGP, but they aren't tested, primarily for CI performance reasons.
*
* @see <a href="https://maven.google.com/web/index.html?q=build#com.android.tools.build:gradle">AGP releases</a>
*/
protected static final SUPPORTED_AGP_VERSIONS = [
AGP_7_4,
// AGP_8_0,
AGP_8_0,
AGP_8_1,
AGP_8_2,
AGP_8_3,
AGP_8_4,
]

protected static List<AgpVersion> agpVersions(AgpVersion minAgpVersion = AgpVersion.AGP_MIN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ final class DuplicateDependencyVersionsSpec extends AbstractAndroidSpec {
.contains(project.expectedOutput)

where:
[gradleVersion, agpVersion] << multivariableDataPipe([GRADLE_7_5], [AGP_7_3.version])
[gradleVersion, agpVersion] << multivariableDataPipe([GRADLE_8_0], [AGP_8_0.version])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import static com.google.common.truth.Truth.assertAbout
@SuppressWarnings("GroovyAssignabilityCheck")
final class IgnoredVariantSpec extends AbstractAndroidSpec {

def "plugin ignore android variants (#gradleVersion AGP #agpVersion ignored debug)"() {
def "can ignore debug variant (#gradleVersion AGP #agpVersion)"() {
given:
def project = new DebugVariantIgnoredProject(agpVersion)
gradleProject = project.gradleProject
Expand All @@ -30,7 +30,7 @@ final class IgnoredVariantSpec extends AbstractAndroidSpec {
[gradleVersion, agpVersion] << gradleAgpMatrix()
}

def "plugin ignore android variants (#gradleVersion AGP #agpVersion ignored release)"() {
def "can ignore release variant (#gradleVersion AGP #agpVersion)"() {
given:
def project = new ReleaseVariantIgnoredProject(agpVersion)
gradleProject = project.gradleProject
Expand All @@ -47,7 +47,7 @@ final class IgnoredVariantSpec extends AbstractAndroidSpec {
[gradleVersion, agpVersion] << gradleAgpMatrix()
}

def "plugin ignore android variants (#gradleVersion AGP #agpVersion ignored all variants)"() {
def "can ignore all (debug and release) variants (#gradleVersion AGP #agpVersion)"() {
given:
def project = new AllVariantsIgnoredProject(agpVersion)
gradleProject = project.gradleProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.Plugin
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.model.ProjectAdvice
import com.autonomousapps.utils.DebugAware

import static com.autonomousapps.AdviceHelper.actualProjectAdvice
import static com.autonomousapps.kit.gradle.dependencies.Dependencies.*
Expand All @@ -37,9 +38,15 @@ abstract class AbstractVariantProject extends AbstractAndroidProject {
}

private GradleProject build() {
def properties = projectGradleProperties
if (!DebugAware.debug) {
// There is a Gradle bug that makes tests break when the test uses CC and we're also debugging
properties += GradleProperties.enableConfigurationCache()
}

return newAndroidGradleProjectBuilder(agpVersion)
.withRootProject { root ->
root.gradleProperties = projectGradleProperties + GradleProperties.enableConfigurationCache()
root.gradleProperties = properties
}
.withAndroidSubproject('app') { a ->
a.sources = sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.autonomousapps.model.ProjectAdvice
import static com.autonomousapps.AdviceHelper.*
import static com.autonomousapps.kit.gradle.Dependency.project
import static com.autonomousapps.kit.gradle.dependencies.Dependencies.appcompat
import static com.autonomousapps.kit.gradle.dependencies.Dependencies.kotlinStdLib

final class DataBindingUsagesExclusionsProject extends AbstractAndroidProject {

Expand Down Expand Up @@ -59,7 +58,6 @@ final class DataBindingUsagesExclusionsProject extends AbstractAndroidProject {
lib.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib, Plugins.kotlinAndroid, Plugins.kapt]
bs.android = defaultAndroidLibBlock(true, 'com.example.lib')
bs.dependencies = libDependencies
bs.withGroovy("android.buildFeatures.dataBinding true")
}
lib.sources = libSources
Expand Down Expand Up @@ -93,9 +91,8 @@ final class DataBindingUsagesExclusionsProject extends AbstractAndroidProject {
]

private List<Dependency> appDependencies = [
kotlinStdLib("implementation"),
appcompat("implementation"),
project("implementation", ":lib"),
appcompat('implementation'),
project('implementation', ':lib'),
]

private libSources = [
Expand All @@ -114,10 +111,6 @@ final class DataBindingUsagesExclusionsProject extends AbstractAndroidProject {
)
]

private List<Dependency> libDependencies = [
kotlinStdLib('api')
]

private final Set<ProjectAdvice> expectedBuildHealthWithExclusions = [
projectAdviceForDependencies(':app', [
Advice.ofRemove(projectCoordinates(':lib'), 'implementation')
Expand Down
22 changes: 16 additions & 6 deletions src/main/kotlin/com/autonomousapps/Flags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package com.autonomousapps

import java.util.Locale
import org.gradle.api.GradleException
import org.gradle.api.Project
import java.util.Locale

object Flags {

Expand All @@ -18,10 +18,14 @@ object Flags {
private const val FLAG_TEST_ANALYSIS = "dependency.analysis.test.analysis"
private const val FLAG_PRINT_BUILD_HEALTH = "dependency.analysis.print.build.health"
private const val FLAG_PROJECT_INCLUDES = "dependency.analysis.project.includes"

/**
* Android build variant to not analyze i.e.
*
* ```
* # gradle.properties
* dependency.analysis.android.ignored.variants=release
* ```
*/
private const val FLAG_ANDROID_IGNORED_VARIANTS = "dependency.analysis.android.ignored.variants"

Expand All @@ -30,7 +34,9 @@ object Flags {
internal fun Project.shouldAnalyzeTests() = getGradleOrSysProp(FLAG_TEST_ANALYSIS, true)
internal fun Project.shouldAutoApply() = getGradleOrSysProp(FLAG_AUTO_APPLY, true)
internal fun Project.printBuildHealth() = getGradlePropForConfiguration(FLAG_PRINT_BUILD_HEALTH, false)
internal fun Project.androidIgnoredVariants() = getGradlePropForConfiguration(FLAG_ANDROID_IGNORED_VARIANTS, "").split(",")
internal fun Project.androidIgnoredVariants() = getGradlePropForConfiguration(
FLAG_ANDROID_IGNORED_VARIANTS, ""
).split(",")

internal fun Project.projectPathRegex(): Regex =
getGradlePropForConfiguration(FLAG_PROJECT_INCLUDES, ".*").toRegex()
Expand All @@ -50,7 +56,9 @@ object Flags {
internal fun Project.compatibility(): Compatibility {
return getGradlePropForConfiguration(FLAG_DISABLE_COMPATIBILITY, Compatibility.WARN.name).let {
@Suppress("DEPRECATION") val value = it.toUpperCase(Locale.US)
Compatibility.values().find { it.name == value } ?: error("Unrecognized value '$it' for 'dependency.analysis.compatibility' property. Allowed values are ${Compatibility.values()}")
Compatibility.values().find { it.name == value } ?: error(
"Unrecognized value '$it' for 'dependency.analysis.compatibility' property. Allowed values are ${Compatibility.values()}"
)
}
}

Expand All @@ -61,8 +69,7 @@ object Flags {
}

private fun Project.getGradlePropForConfiguration(name: String, default: String): String =
providers.gradleProperty(name)
.getOrElse(default)
providers.gradleProperty(name).getOrElse(default)

private fun Project.getGradlePropForConfiguration(name: String, default: Boolean): Boolean =
getGradlePropForConfiguration(name, default.toString()).toBoolean()
Expand All @@ -73,6 +80,9 @@ object Flags {
.toBoolean()

internal enum class Compatibility {
NONE, DEBUG, WARN, ERROR
NONE,
DEBUG,
WARN,
ERROR
}
}
Loading
Loading