I have the following project structure
root-project
│ build.gradle.kts
│
└───multiplatform-project
│ │ build.gradle.kts
│ │
│ └───src
│ │ kotlin
| | js
│
└───simple-kotlin-project
│ build.gradle.kts
So there are 3 projects in total (3 build.gradle.kts
files).
Here is the root project
build.gradle.kts
plugins { kotlin("jvm") version kotlinVersion apply false kotlin("kapt") version kotlinVersion apply false kotlin("multiplatform") version kotlinVersion apply false } subprojects { apply<JavaPlugin>() if (name.contains("multiplatform-project")) { apply(plugin = "org.jetbrains.kotlin.multiplatform") } else { apply(plugin = "kotlin") } apply(plugin = "kotlin-kapt") dependencies { implementation(kotlin("stdlib")) implementation(kotlin("reflect")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M2") implementation("org.slf4j:slf4j-api:1.7.25") implementation("ch.qos.logback:logback-core:1.2.3") implementation("ch.qos.logback:logback-classic:1.2.3") testImplementation("junit:junit:$jUnitVersion") } }
Here is the simple kotlin project that uses kapt and that works
val jacksonVersion: String by project dependencies { implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") kapt(project(":generator")) // THIS WORKS!!! }
Now my question is how to make this work in the multiplatorm project which looks like that
val jacksonVersion: String by project val ktorVersion: String by project kotlin { jvm { val main by compilations.getting { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() } compileKotlinTask output } } js {} sourceSets { val jvmMain by getting { dependencies { implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") implementation("io.ktor:ktor-html-builder:$ktorVersion") implementation("io.ktor:ktor-server-netty:$ktorVersion") kapt(project(":generator")) // THIS DOESN'T WORK!!! } } } }
Here is the error that I see in IDEA
That is not a phantom error. If I run gradle build, I get the following error:
build.gradle.kts:38:22: Type mismatch: inferred type is ProjectDependency but Action was expected
So, the question boils down to how do I run kapt plugin on the kotlin sourceSet the same way that I can do it in a simple kotlin project by adding it to dependencies of the project.