From 6db82349ef7468a18345a5f44456de16fcc10b02 Mon Sep 17 00:00:00 2001 From: Alexey Illarionov Date: Sat, 13 Jan 2024 15:43:24 +0300 Subject: [PATCH] Move configuration of generator modules to precompiled script plugin (#3) --- activity/generator/build.gradle.kts | 21 +---------- experiment/generator/build.gradle.kts | 21 +---------- ...uild-logic.project.auto.service.gradle.kts | 23 ++++++++++++ ...n.build-logic.project.generator.gradle.kts | 37 +++++++++++++++++++ ...ld-logic.project.kotlin.library.gradle.kts | 5 +++ ...odegen.build-logic.project.test.gradle.kts | 1 - gradle/verification-metadata.xml | 5 +++ initializer/generator/build.gradle.kts | 21 +---------- viewmodel/generator/build.gradle.kts | 21 +---------- workmanager/generator/build.gradle.kts | 21 +---------- 10 files changed, 75 insertions(+), 101 deletions(-) create mode 100644 gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.auto.service.gradle.kts create mode 100644 gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.generator.gradle.kts diff --git a/activity/generator/build.gradle.kts b/activity/generator/build.gradle.kts index 2a718d7..24423ba 100644 --- a/activity/generator/build.gradle.kts +++ b/activity/generator/build.gradle.kts @@ -5,27 +5,8 @@ */ plugins { - id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") - id("ru.pixnews.anvil.codegen.build-logic.project.test") - id("ru.pixnews.anvil.codegen.build-logic.project.publish") - kotlin("kapt") + id("ru.pixnews.anvil.codegen.build-logic.project.generator") } group = "ru.pixnews.anvil.codegen.activity.generator" version = "0.1-SNAPSHOT" - -dependencies { - api(libs.anvil.compiler.api) - implementation(libs.anvil.compiler.utils) - implementation(libs.kotlinpoet) { exclude(module = "kotlin-reflect") } - implementation(projects.common) - - compileOnly(libs.auto.service.annotations) - kapt(libs.auto.service.compiler) - - testImplementation(libs.anvil.annotations.optional) - testImplementation(libs.assertk) - testImplementation(libs.dagger) - testImplementation(projects.testUtils) - testImplementation(testFixtures(libs.anvil.compiler.utils)) -} diff --git a/experiment/generator/build.gradle.kts b/experiment/generator/build.gradle.kts index 3290892..718f509 100644 --- a/experiment/generator/build.gradle.kts +++ b/experiment/generator/build.gradle.kts @@ -5,27 +5,8 @@ */ plugins { - id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") - id("ru.pixnews.anvil.codegen.build-logic.project.test") - id("ru.pixnews.anvil.codegen.build-logic.project.publish") - kotlin("kapt") + id("ru.pixnews.anvil.codegen.build-logic.project.generator") } group = "ru.pixnews.anvil.codegen.experiment.generator" version = "0.1-SNAPSHOT" - -dependencies { - api(libs.anvil.compiler.api) - implementation(libs.anvil.compiler.utils) - implementation(libs.kotlinpoet) { exclude(module = "kotlin-reflect") } - implementation(projects.common) - - compileOnly(libs.auto.service.annotations) - kapt(libs.auto.service.compiler) - - testImplementation(libs.anvil.annotations.optional) - testImplementation(libs.assertk) - testImplementation(libs.dagger) - testImplementation(projects.testUtils) - testImplementation(testFixtures(libs.anvil.compiler.utils)) -} diff --git a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.auto.service.gradle.kts b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.auto.service.gradle.kts new file mode 100644 index 0000000..9084870 --- /dev/null +++ b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.auto.service.gradle.kts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, the pixnews-anvil-codegen project authors and contributors. + * Please see the AUTHORS file for details. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ + +import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin + +/** + * Convention plugin that adds Auto-Service + */ +plugins { + `java-library` + kotlin("kapt") +} + +plugins.withType { + dependencies { + val libs = versionCatalogs.named("libs") + compileOnly(libs.findLibrary("auto.service.annotations").get()) + add("kapt", libs.findLibrary("auto.service.compiler").get()) + } +} diff --git a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.generator.gradle.kts b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.generator.gradle.kts new file mode 100644 index 0000000..2682046 --- /dev/null +++ b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.generator.gradle.kts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024, the pixnews-anvil-codegen project authors and contributors. + * Please see the AUTHORS file for details. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ + +import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo + +/** + * Convention plugin for use in kotlin generator modules + */ +plugins { + id("ru.pixnews.anvil.codegen.build-logic.project.auto.service") + id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") + id("ru.pixnews.anvil.codegen.build-logic.project.publish") + id("ru.pixnews.anvil.codegen.build-logic.project.test") +} + +dependencies { + val libs = versionCatalogs.named("libs") + + api(libs.findLibrary("anvil.compiler.api").get()) + addDependencyTo( + this, + "implementation", + libs.findLibrary("kotlinpoet").get().get(), + ) { + exclude(module = "kotlin-reflect") + } + implementation(project(":common")) + + testImplementation(libs.findLibrary("anvil.annotations.optional").get()) + testImplementation(libs.findLibrary("assertk").get()) + testImplementation(libs.findLibrary("dagger").get()) + testImplementation(project(":test-utils")) + testImplementation(testFixtures(libs.findLibrary("anvil.compiler.utils").get())) +} diff --git a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.kotlin.library.gradle.kts b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.kotlin.library.gradle.kts index 7989790..8085953 100644 --- a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.kotlin.library.gradle.kts +++ b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.kotlin.library.gradle.kts @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2024, the pixnews-anvil-codegen project authors and contributors. + * Please see the AUTHORS file for details. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode import org.jetbrains.kotlin.gradle.dsl.JvmTarget diff --git a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.test.gradle.kts b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.test.gradle.kts index bbba914..84e55fc 100644 --- a/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.test.gradle.kts +++ b/gradle/build-logic/project/kotlin/src/main/kotlin/ru.pixnews.anvil.codegen.build-logic.project.test.gradle.kts @@ -51,7 +51,6 @@ testing { "assertk", "junit.jupiter.api", "junit.jupiter.params", - "kotlin.compile.testing", ).forEach { implementation(libs.findLibrary(it).get()) } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index c52264f..f137f67 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -139,6 +139,11 @@ + + + + + diff --git a/initializer/generator/build.gradle.kts b/initializer/generator/build.gradle.kts index 37b4dec..f46ec5a 100644 --- a/initializer/generator/build.gradle.kts +++ b/initializer/generator/build.gradle.kts @@ -5,27 +5,8 @@ */ plugins { - id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") - id("ru.pixnews.anvil.codegen.build-logic.project.test") - id("ru.pixnews.anvil.codegen.build-logic.project.publish") - kotlin("kapt") + id("ru.pixnews.anvil.codegen.build-logic.project.generator") } group = "ru.pixnews.anvil.codegen.initializer.generator" version = "0.1-SNAPSHOT" - -dependencies { - api(libs.anvil.compiler.api) - implementation(libs.anvil.compiler.utils) - implementation(libs.kotlinpoet) { exclude(module = "kotlin-reflect") } - implementation(projects.common) - - compileOnly(libs.auto.service.annotations) - kapt(libs.auto.service.compiler) - - testImplementation(libs.anvil.annotations.optional) - testImplementation(libs.assertk) - testImplementation(libs.dagger) - testImplementation(projects.testUtils) - testImplementation(testFixtures(libs.anvil.compiler.utils)) -} diff --git a/viewmodel/generator/build.gradle.kts b/viewmodel/generator/build.gradle.kts index 2b76d21..a4ed3c9 100644 --- a/viewmodel/generator/build.gradle.kts +++ b/viewmodel/generator/build.gradle.kts @@ -5,27 +5,8 @@ */ plugins { - id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") - id("ru.pixnews.anvil.codegen.build-logic.project.test") - id("ru.pixnews.anvil.codegen.build-logic.project.publish") - kotlin("kapt") + id("ru.pixnews.anvil.codegen.build-logic.project.generator") } group = "ru.pixnews.anvil.codegen.viewmodel.generator" version = "0.1-SNAPSHOT" - -dependencies { - api(libs.anvil.compiler.api) - implementation(libs.anvil.compiler.utils) - implementation(libs.kotlinpoet) { exclude(module = "kotlin-reflect") } - implementation(projects.common) - - compileOnly(libs.auto.service.annotations) - kapt(libs.auto.service.compiler) - - testImplementation(libs.anvil.annotations.optional) - testImplementation(libs.assertk) - testImplementation(libs.dagger) - testImplementation(projects.testUtils) - testImplementation(testFixtures(libs.anvil.compiler.utils)) -} diff --git a/workmanager/generator/build.gradle.kts b/workmanager/generator/build.gradle.kts index 3a364b9..bbef8d5 100644 --- a/workmanager/generator/build.gradle.kts +++ b/workmanager/generator/build.gradle.kts @@ -5,27 +5,8 @@ */ plugins { - id("ru.pixnews.anvil.codegen.build-logic.project.kotlin.library") - id("ru.pixnews.anvil.codegen.build-logic.project.test") - id("ru.pixnews.anvil.codegen.build-logic.project.publish") - kotlin("kapt") + id("ru.pixnews.anvil.codegen.build-logic.project.generator") } group = "ru.pixnews.anvil.codegen.workamanger.generator" version = "0.1-SNAPSHOT" - -dependencies { - api(libs.anvil.compiler.api) - implementation(libs.anvil.compiler.utils) - implementation(libs.kotlinpoet) { exclude(module = "kotlin-reflect") } - implementation(projects.common) - - compileOnly(libs.auto.service.annotations) - kapt(libs.auto.service.compiler) - - testImplementation(libs.anvil.annotations.optional) - testImplementation(libs.assertk) - testImplementation(libs.dagger) - testImplementation(projects.testUtils) - testImplementation(testFixtures(libs.anvil.compiler.utils)) -}