Skip to content

Commit

Permalink
Add check if "test" target exist #638
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso committed Aug 31, 2024
1 parent eb9b5a5 commit b832820
Showing 1 changed file with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ class KtorfitGradlePlugin : Plugin<Project> {

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) {
Expand All @@ -65,12 +51,11 @@ class KtorfitGradlePlugin : Plugin<Project> {
}

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()) {
Expand All @@ -81,10 +66,7 @@ class KtorfitGradlePlugin : Plugin<Project> {
it.toString()
}
}
dependencies.add(
"ksp$capitalizedTargetName",
dependency,
)
dependencies.add("ksp$capitalizedTargetName", dependency)

if (this.compilations.any { it.name == "test" }) {
dependencies.add(
Expand All @@ -109,6 +91,20 @@ class KtorfitGradlePlugin : Plugin<Project> {

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(),
)
}
}
}
}
Expand Down

0 comments on commit b832820

Please sign in to comment.