refactor(build): use typed catalog in build-logic

This commit is contained in:
Harsh Shandilya 2023-11-28 11:49:47 +05:30
parent a9b0112279
commit f3bc261f37
No known key found for this signature in database
3 changed files with 13 additions and 18 deletions

View file

@ -91,4 +91,7 @@ dependencies {
implementation(libs.build.vcu)
implementation(libs.build.versions)
implementation(libs.kotlinx.coroutines.core)
// Expose the generated version catalog API to the plugin.
implementation(files(libs::class.java.superclass.protectionDomain.codeSource.location))
}

View file

@ -5,12 +5,11 @@ import app.passwordstore.gradle.flavors.configureSlimTests
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.TestedExtension
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
object AndroidCommon {
@ -47,11 +46,10 @@ object AndroidCommon {
}
project.extensions.findByType<ApplicationExtension>()?.run { lint.configureLint(project) }
project.extensions.findByType<LibraryExtension>()?.run { lint.configureLint(project) }
val lintDepKeys = listOf("thirdparty-compose-lints", "thirdparty-slack-lints")
val catalog = project.extensions.getByType<VersionCatalogsExtension>()
val libs = catalog.named("libs")
lintDepKeys.forEach { key ->
project.dependencies.addProvider("lintChecks", libs.findLibrary(key).get())
val libs = project.extensions.getByName("libs") as LibrariesForLibs
project.dependencies.apply {
addProvider("lintChecks", libs.thirdparty.compose.lints)
addProvider("lintChecks", libs.thirdparty.slack.lints)
}
}
}

View file

@ -6,11 +6,9 @@
package app.passwordstore.gradle
import app.passwordstore.gradle.KotlinCommonPlugin.Companion.JVM_TOOLCHAIN_ACTION
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.artifacts.VersionConstraint
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
@ -27,10 +25,9 @@ class KotlinAndroidPlugin : Plugin<Project> {
apply(KotlinCommonPlugin::class)
}
project.extensions.getByType<KotlinProjectExtension>().jvmToolchain(JVM_TOOLCHAIN_ACTION)
val catalog = project.extensions.getByType<VersionCatalogsExtension>()
val libs = catalog.named("libs")
val composeCompilerVersion = libs.getVersion("composeCompiler")
val kotlinVersion = libs.getVersion("kotlin")
val libs = project.extensions.getByName("libs") as LibrariesForLibs
val composeCompilerVersion = libs.versions.composeCompiler.get()
val kotlinVersion = libs.versions.kotlin.get()
val matches = COMPOSE_COMPILER_VERSION_REGEX.find(composeCompilerVersion)
if (matches != null) {
@ -46,11 +43,8 @@ class KotlinAndroidPlugin : Plugin<Project> {
}
}
private fun VersionCatalog.getVersion(key: String) =
findVersion(key).map(VersionConstraint::toString).get()
private companion object {
// Matches against 1.5.0-dev-k1.9.0-6a60475e07f
val COMPOSE_COMPILER_VERSION_REGEX = "\\d.\\d.\\d-dev-k(\\d.\\d.\\d)-[a-z0-9]+".toRegex()
val COMPOSE_COMPILER_VERSION_REGEX = "\\d.\\d.\\d-dev-k(\\d.\\d.\\d+)-[a-z0-9]+".toRegex()
}
}