From 5308640c5e323384c4304a6e0fe4faf6bdbbf8e5 Mon Sep 17 00:00:00 2001 From: "harry.tumalewa" Date: Sun, 26 Apr 2026 18:12:13 +0700 Subject: [PATCH] refactor: Ensure moduleName check is only applied to contributors + update README --- README.md | 8 ++++++++ gradle/libs.versions.toml | 1 + samples/core/build.gradle.kts | 5 +---- samples/feature/home/build.gradle.kts | 5 +---- .../com/harrytmthy/stitch/ksp/StitchSymbolProcessor.kt | 10 +++++----- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 023c797..2125d21 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,14 @@ Build, then initialize the generated root graph: StitchInjector.init(StitchSingletonGraph()) ``` +For multi-module projects, other modules should apply this Gradle plugin: + +```kotlin +plugins { + id("io.github.harrytmthy.stitch") version "1.0.0-rc01" +} +``` + Add other scopes, where each scope represents a generated graph: ```kotlin diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4ff4595..823ee6a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -57,6 +57,7 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref koin-compiler = { id = "io.insert-koin.compiler.plugin", version.ref = "koinCompiler" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublishPlugin" } +stitch = { id = "io.github.harrytmthy.stitch", version.ref = "stitch" } # Convention Plugins stitch-android-library = { id = "stitch.android.library" } diff --git a/samples/core/build.gradle.kts b/samples/core/build.gradle.kts index f9d90b9..0c56a5b 100644 --- a/samples/core/build.gradle.kts +++ b/samples/core/build.gradle.kts @@ -17,6 +17,7 @@ plugins { alias(libs.plugins.stitch.android.library) alias(libs.plugins.ksp) + alias(libs.plugins.stitch) } android { @@ -28,10 +29,6 @@ android { create("withDagger") { dimension = "di" } create("withNone") { dimension = "di" } } - - ksp { - arg("stitch.moduleName", "Core") - } } dependencies { diff --git a/samples/feature/home/build.gradle.kts b/samples/feature/home/build.gradle.kts index 8348f9d..13bcc8f 100644 --- a/samples/feature/home/build.gradle.kts +++ b/samples/feature/home/build.gradle.kts @@ -17,6 +17,7 @@ plugins { alias(libs.plugins.stitch.android.library) alias(libs.plugins.ksp) + alias(libs.plugins.stitch) } android { @@ -28,10 +29,6 @@ android { create("withDagger") { dimension = "di" } create("withNone") { dimension = "di" } } - - ksp { - arg("stitch.moduleName", "FeatureHome") - } } dependencies { diff --git a/stitch-ksp/src/main/kotlin/com/harrytmthy/stitch/ksp/StitchSymbolProcessor.kt b/stitch-ksp/src/main/kotlin/com/harrytmthy/stitch/ksp/StitchSymbolProcessor.kt index 9c2a66f..8ff5f94 100644 --- a/stitch-ksp/src/main/kotlin/com/harrytmthy/stitch/ksp/StitchSymbolProcessor.kt +++ b/stitch-ksp/src/main/kotlin/com/harrytmthy/stitch/ksp/StitchSymbolProcessor.kt @@ -46,11 +46,11 @@ class StitchSymbolProcessor(private val environment: SymbolProcessorEnvironment) val logger = environment.logger logger.info("Stitch: Starting dependency injection code generation") try { - val moduleName = getOption("stitch.moduleName") - val moduleKey = moduleName.toModuleKey() val localScanResult = LocalScanResult() LocalAnnotationScanner(resolver, localScanResult).scan() if (!localScanResult.isAggregator) { + val moduleName = getModuleName() + val moduleKey = moduleName.toModuleKey() ContributionCodeGenerator(environment.codeGenerator) .generate(moduleName, moduleKey, localScanResult) } else { @@ -76,9 +76,9 @@ class StitchSymbolProcessor(private val environment: SymbolProcessorEnvironment) return emptyList() } - private fun getOption(name: String): String = - environment.options[name] ?: throw StitchProcessingException( - "Missing KSP option '$name'. Configure via ksp { arg(...) } or apply 'io.github.harrytmthy.stitch' plugin.", + private fun getModuleName(): String = + environment.options["stitch.moduleName"] ?: throw StitchProcessingException( + "Missing KSP option 'stitch.moduleName'. Configure via ksp { arg(...) } or apply 'io.github.harrytmthy.stitch' plugin.", ) /**