build-logic: rewrite version overrides to edit the version catalog

This commit is contained in:
Harsh Shandilya 2022-06-12 16:31:42 +05:30
parent e07b239360
commit 68cf22fb75
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
5 changed files with 17 additions and 32 deletions

View file

@ -42,6 +42,7 @@ jobs:
- name: Run checks
uses: gradle/gradle-build-action@v2.2.0
env:
GRADLE_VERSION_OVERRIDE_com_android_tools_build_gradle: ${{ matrix.agp-version }}
DEP_OVERRIDE: true
DEP_OVERRIDE_agp: ${{ matrix.agp-version }}
with:
arguments: check

View file

@ -59,17 +59,3 @@ dependencies {
implementation(libs.build.semver)
implementation(libs.build.sentry)
}
configurations.all {
resolutionStrategy.eachDependency {
val overrideName =
"GRADLE_VERSION_OVERRIDE_${requested.group.replace('.', '_')}_${requested.name}"
val overridenVersion = System.getenv(overrideName)
if (!overridenVersion.isNullOrEmpty()) {
project.logger.lifecycle(
"Overriding dependency ${requested.group}:${requested.name} to version $overridenVersion"
)
useVersion(overridenVersion)
}
}
}

View file

@ -59,17 +59,3 @@ dependencies {
implementation(libs.build.kotlin)
implementation(libs.build.spotless)
}
configurations.all {
resolutionStrategy.eachDependency {
val overrideName =
"GRADLE_VERSION_OVERRIDE_${requested.group.replace('.', '_')}_${requested.name}"
val overridenVersion = System.getenv(overrideName)
if (!overridenVersion.isNullOrEmpty()) {
project.logger.lifecycle(
"Overriding dependency ${requested.group}:${requested.name} to version $overridenVersion"
)
useVersion(overridenVersion)
}
}
}

View file

@ -27,7 +27,19 @@ dependencyResolutionManagement {
}
mavenCentral()
}
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
versionCatalogs {
maybeCreate("libs").apply {
from(files("../gradle/libs.versions.toml"))
if (System.getenv("DEP_OVERRIDE") == "true") {
val overrides = System.getenv().filterKeys { it.startsWith("DEP_OVERRIDE_") }
for ((key, value) in overrides) {
val catalogKey = key.removePrefix("DEP_OVERRIDE_").toLowerCase()
println("Overriding $catalogKey with $value")
version(catalogKey, value)
}
}
}
}
}
include("android-plugins")

View file

@ -1,5 +1,5 @@
# Centralized versions for dependencies that share versions
[versions]
agp = "7.2.1"
androidx_activity = "1.5.0-rc01"
compose = "1.2.0-alpha08"
coroutines = "1.6.2"
@ -38,7 +38,7 @@ androidx-swiperefreshlayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.
aps-sublimeFuzzy = "com.github.android-password-store:sublime-fuzzy:2.2.0"
aps-zxingAndroidEmbedded = "com.github.android-password-store:zxing-android-embedded:4.2.1"
build-agp = "com.android.tools.build:gradle:7.2.1"
build-agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
build-binarycompat = "org.jetbrains.kotlinx:binary-compatibility-validator:0.10.0"
build-download = "de.undercouch:gradle-download-task:5.1.0"
build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }