Skip to content

Annotation Processor Setup

MerlinTHS edited this page Feb 17, 2023 · 1 revision

To use the annotations and the corresponding processor to generate extensions

  • Apply the KSP Compiler - Plugin
  • Include the annotations - dependency.
  • Add the generated directory to your source sets.

For jvm single-platform projects.

plugins {
    id("com.google.devtools.ksp") version "1.8.0-1.0.8"
}

implementation {
    implementation("io.github.merlinths:kava-annotations:1.0.3")
    
    add("ksp", "io.github.merlinths:kava-processor:1.0.0")
    add("kspTest", "io.github.merlinths:kava-processor:1.0.0")
}

kotlin {
    sourceSets {
        main {
            kotlin.srcDir("build/generated/ksp/main/kotlin")
        }

        test {
            kotlin.srcDir("build/generated/ksp/test/kotlin")
        }
    }
}

For a multi-platform projects.

plugins {
  id("com.google.devtools.ksp") version "1.8.0-1.0.8"
}

kotlin {
    jvm {
        compilations.all {
            kotlinOptions {
                freeCompilerArgs = listOf("-Xcontext-receivers")
            }
        }
    }

    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation("io.github.merlinths:kava-core:1.0.0")
                implementation("io.github.merlinths:kava-annotations:1.0.3")
            }

            kotlin.srcDir("build/generated/ksp/jvm/jvmMain")
        }
        val jvmTest by getting {
            dependencies {
                implementation("io.github.merlinths:kava-core:1.0.0")
                implementation("io.github.merlinths:kava-annotations:1.0.3")
            }

            kotlin.srcDir("build/generated/ksp/jvm/jvmTest")
        }
    }
}

dependencies {
    add("kspJvm", "io.github.merlinths:kava-processor:1.0.0")
    add("kspJvmTest", "io.github.merlinths:kava-processor:1.0.0")
}

Clone this wiki locally