From b832820586defca1b42418a47a9c9b06361f6539 Mon Sep 17 00:00:00 2001 From: Jens Klingenberg Date: Sat, 31 Aug 2024 11:53:48 +0200 Subject: [PATCH] Add check if "test" target exist #638 --- .../ktorfit/gradle/KtorfitGradlePlugin.kt | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt b/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt index eb9eebb75..8ddae99f0 100644 --- a/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt +++ b/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt @@ -43,20 +43,6 @@ class KtorfitGradlePlugin : Plugin { checkKSPVersion(kspVersion) - val kspExtension = extensions.findByName("ksp") ?: error("KSP config not found") - val argMethod = kspExtension.javaClass.getMethod("arg", String::class.java, String::class.java) - - afterEvaluate { - val config = getKtorfitConfig() - - argMethod.invoke(kspExtension, "Ktorfit_Errors", config.errorCheckingMode.ordinal.toString()) - argMethod.invoke( - kspExtension, - "Ktorfit_QualifiedTypeName", - config.generateQualifiedTypeName.toString(), - ) - } - val dependency = "$ktorfitKsp:$KTORFIT_VERSION-$kspVersion$SNAPSHOT" when (val kotlinExtension = kotlinExtension) { @@ -65,12 +51,11 @@ class KtorfitGradlePlugin : Plugin { } is KotlinMultiplatformExtension -> { - dependencies { - add("kspCommonMainMetadata", dependency) - } - kotlinExtension.targets.configureEach { - if (targetName == "metadata") return@configureEach + if (platformType.name == "common") { + dependencies.add("kspCommonMainMetadata", dependency) + return@configureEach + } val capitalizedTargetName = targetName.replaceFirstChar { if (it.isLowerCase()) { @@ -81,10 +66,7 @@ class KtorfitGradlePlugin : Plugin { it.toString() } } - dependencies.add( - "ksp$capitalizedTargetName", - dependency, - ) + dependencies.add("ksp$capitalizedTargetName", dependency) if (this.compilations.any { it.name == "test" }) { dependencies.add( @@ -109,6 +91,20 @@ class KtorfitGradlePlugin : Plugin { else -> Unit } + + val kspExtension = extensions.findByName("ksp") ?: error("KSP config not found") + val argMethod = kspExtension.javaClass.getMethod("arg", String::class.java, String::class.java) + + afterEvaluate { + val config = getKtorfitConfig() + + argMethod.invoke(kspExtension, "Ktorfit_Errors", config.errorCheckingMode.ordinal.toString()) + argMethod.invoke( + kspExtension, + "Ktorfit_QualifiedTypeName", + config.generateQualifiedTypeName.toString(), + ) + } } } }