diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2023-11-28 11:49:47 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2023-11-28 11:49:47 +0530 |
commit | f3bc261f37929e683f69a0ea8ba87759d28d596f (patch) | |
tree | e78fd99b93168562b7a1ff609864cde9636ce71c /build-logic | |
parent | a9b0112279bca0f19a2d8756d2fa4498936660dd (diff) |
refactor(build): use typed catalog in build-logic
Diffstat (limited to 'build-logic')
3 files changed, 13 insertions, 18 deletions
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index b5e2ed8f..a3914ac8 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -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)) } diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/AndroidCommon.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/AndroidCommon.kt index c1311f41..7157d3ae 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/AndroidCommon.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/AndroidCommon.kt @@ -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) } } } diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt index a80a5807..ead89705 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt @@ -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() } } |