hi, I am trying to make a multiplatform project wi...
# kapt
a
hi, I am trying to make a multiplatform project with jvm and androidTarget - in the Android part I use Hilt to annotate some shared viewmodels, this works fine when running on android, but when trying to build jvm target it fails:
Copy code
Execution failed for task ':moduleName:kaptKotlinJvm'.
> Cannot query the value of this provider because it has no value available.
  The value of this provider is derived from:
    - task ':moduleName:kaptGenerateStubsKotlinJvm' property 'kotlinCompileDestinationDirectory'
If I remove Kapt plugin it works on jvm, but the Hilt kapt tasks won’t be run and I get runtime error when using viewModel on Android. this is the build.gradle.kts file:
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    kotlin("kapt")
}

kotlin {
    jvm()
    androidTarget()

    sourceSets {

        val commonMain by getting {
            dependencies {
                implementation(Deps.kotlinCoroutines)
            }
        }

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }

        val jvmMain by getting {
            dependencies {
                implementation(Deps.voyagerNavigator)
                implementation(Deps.voyagerKoin)
            }
        }

        val androidMain by getting {
            kotlin.srcDir("src/commonMain/kotlin")
            dependencies {
                implementation(Deps.kotlinCoroutinesAndroid)
                implementation(Deps.androidxLifecycleViewModel)
                implementation(Deps.googleHilt)
                configurations["kapt"]?.dependencies?.add(project.dependencies.create(Deps.googleHiltCompiler))
            }
        }
    }
}

android {
    namespace = "package"
    compileSdk = ConfigData.androidCompileSdkVersion

    defaultConfig {
        minSdk = ConfigData.androidMinSdkVersion
    }
    sourceSets["main"].apply {
        manifest.srcFile("src/androidMain/AndroidManifest.xml")
        res.srcDirs("src/androidMain/resources")
        resources.srcDirs("src/commonMain/resources")
    }
    compileOptions {
        sourceCompatibility = Versions.javaVersion
        targetCompatibility = Versions.javaVersion
    }
    kotlin {
        jvmToolchain(Versions.javaJvmTarget.toInt())
    }
}
t
Should be fixed in 1.9.20-beta
m
Hi, Having the same issue. Tested with 1.9.20-beta and 1.9.20-RC2, and it reproduces there.
t
@Mikhail do you have a repro project?
m
It is huge and complicated. It would be difficult to trim it to minimal reproducible example. If there is any workaround, I can try to apply it and retest. Otherwise I can't tell how soon I can provide repro project.
t
ah, sorry. I've understand what is going on
basically in MPP it is not possible to use Kapt with Android and JVM in the same module. Let me find related issue
This is the main issue: https://youtrack.jetbrains.com/issue/KT-30878 For kapt task configuration error I will create a separate issue, but it will not solve the main one
basically workaround for now to use separate Gradle modules for JVM and Android sad panda
m
It works fine with 1.8.22. Only start appearing during migration to 1.9.10 It is indeed kmp project with jvm and android targets.
t
annotation processors could also generate Java code - that is why kapt requires
withJava()
which is not working with JVM + Android. Probably we could add some switch that should be explicitly turned on when all AP generates Kotlin code.
a
My workaround is not pretty, but I basically disallow applying kapt plugin for specific taskNames (if some have a solution for a nicer workaround that would be appreciated):
Copy code
if (gradle.startParameter.taskNames.contains("desktop:run")) {
   println("Running without kapt")
} else {
   println("Running with kapt for task ${gradle.startParameter.taskNames.firstOrNull()}")
   apply(plugin = "kotlin-kapt")
}
306 Views