Skip to content

Commit

Permalink
KSP gradle plugin multiplatform target
Browse files Browse the repository at this point in the history
  • Loading branch information
programadorthi committed Nov 15, 2024
1 parent 7ec2b89 commit 4d75c3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import java.util.Locale

@Suppress("unused")
class KotlinRoutingGradlePlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -16,16 +17,12 @@ class KotlinRoutingGradlePlugin : Plugin<Project> {

val kex = kotlinExtension
if (kex is KotlinSingleTargetExtension<*>) {
dependencies.add("implementation", ANNOTATIONS)
dependencies.add("ksp", PROCESSOR)
return@with
}

if (kex is KotlinMultiplatformExtension) {
kex.targets.configureEach { kTarget ->
kTarget.compilations.configureEach { compilation ->
println(">>>> $kTarget -> $compilation")
}
if (kTarget.platformType.name == "common") {
dependencies.add("kspCommonMainMetadata", PROCESSOR)
return@configureEach
Expand All @@ -50,7 +47,6 @@ class KotlinRoutingGradlePlugin : Plugin<Project> {

private companion object {
// Version will be replaced by Gradle Exec Task
private const val ANNOTATIONS = "dev.programadorthi.routing:ksp-core-annotations:<version>"
private const val PROCESSOR = "dev.programadorthi.routing:ksp-core-processor:<version>"
}
}
24 changes: 20 additions & 4 deletions samples/ksp-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
kotlin("jvm")
kotlin("multiplatform")
alias(libs.plugins.ksp)
//id("dev.programadorthi.routing") version "0.0.99"
id("dev.programadorthi.routing") version "0.0.99"
}

dependencies {
implementation(projects.core)
kotlin {
jvm {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
mainRun {
mainClass.set("MainKt")
}
}

sourceSets {
commonMain {
dependencies {
implementation(projects.core)
implementation(projects.ksp.coreAnnotations)
}
}
}
}

configurations.all {
Expand Down
File renamed without changes.

0 comments on commit 4d75c3d

Please sign in to comment.