Hello again, I'm having trouble with setting up KS...
# gradle
a
Hello again, I'm having trouble with setting up KSP for my project. How can I resolve this?
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:compileJava
\--- :compileKotlinJvm
     \--- :kspCommonMainKotlinMetadata
          +--- :jvmJar
          |    +--- :compileJava (*)
          |    +--- :compileKotlinJvm (*)
          |    \--- :jvmMainClasses
          |         +--- :compileJava (*)
          |         \--- :compileKotlinJvm (*)
          \--- :ksp:jvmJar
               +--- :ksp:compileJava
               |    +--- :jvmJar (*)
               |    \--- :ksp:compileKotlinJvm
               |         \--- :jvmJar (*)
               +--- :ksp:compileKotlinJvm (*)
               \--- :ksp:jvmMainClasses
                    +--- :ksp:compileJava (*)
                    \--- :ksp:compileKotlinJvm (*)

(*) - details omitted (listed previously)
I put my annotation for ksp in the same module as the ksp processor itself, is this fine?
Top-level build file:
Copy code
plugins {
  kotlin("multiplatform") version "1.9.22"
  id("com.google.devtools.ksp") version "1.9.22-1.0.18"
  /* ... */
}

repositories {
  /* ... */
}

kotlin {
  jvm {
    withJava()

    compilations.all {
      kotlinOptions.jvmTarget = "17"
    }
  } // i'm unsure whether i need to add jvm as a target in order for ksp to work. project does not rely on jvm
  val mingwTarget = mingwX64()
  
  sourceSets {
    val commonMain by getting {
      kotlin.srcDir("build/generated/ksp/commonMain/kotlin")

      dependencies {
        implementation("dev.kord:kord-core:feature-native-SNAPSHOT")
      }
    }
    
    mingwTarget.apply {
      compilations["main"].defaultSourceSet.apply {
        dependsOn(commonMain)
      }
    }
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
      if (name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
      }
    }
  }
}

dependencies {
  add("kspCommonMainMetadata", project(":ksp"))
}
:ksp
submodule build file:
Copy code
plugins {
    kotlin("multiplatform") version "1.9.22"
}

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        withJava()
        
        compilations.all {
            kotlinOptions.jvmTarget = "17"
        }
    }
    
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation("com.google.devtools.ksp:symbol-processing-api:1.9.22-1.0.18")
                implementation("com.squareup:kotlinpoet:1.16.0")
                implementation("com.squareup:kotlinpoet-ksp:1.16.0")
                implementation(project(":"))
            }

            kotlin.srcDir("src/jvmMain/kotlin")
            resources.srcDir("src/jvmMain/resources")
        }
    }
}
v
I think the problem is your
implementation(project(":"))
. If you need the
:ksp
result to compile
:
but
:ksp
needs
:
to compile, you are in chicken-and-egg situation.
a
Oh hmm. I was passing in the necessary types from the root module to the ksp. Should I hard-code it instead? Though, there should be a better way.
v
I have no idea, I never used ksp. Just showing you where your chicken-and-egg problem is. 🙂
e
either separate the common classes to another module which is built without that processor and then can be used as a dependency in both, or hard-code the package/class names in the processor (or make it configurable as a processor argument and set it in the module's buildscript)
thank you color 1