Unit Test Failing for Kotlin-Gradle - kotlin

Error :
java.lang.IncompatibleClassChangeError: Found interface kotlin.time.TimeMark, but class was expected
at io.kotest.engine.spec.interceptor.SpecFinishedInterceptor.intercept-0E7RQCE(SpecFinishedInterceptor.kt:37)
Tried Upgrading Kotlin version from :
val kotestVersion = "5.3.0" to val kotestVersion = "5.5.0"
but no luck
Also tried upgrading KotlinJvm Version but no success :
Current ->
kotlin("jvm") version "1.6.21"
Any pointers would be appreciated

Related

"Module was compiled with an incompatible version of Kotlin." - the case with "build.gradle.kts" file

My IntelliJ IDEA plugin based on official Kotlin template. I had no Kotlin experience until tried to develop the plugin for IntelliJ IDEA.
I got the error:
C:/Users/I/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.2/42c296374014a649785bb84aa6d8dc2d18f2ca0e/ideaIC-2022.2/lib/3rd-party-rt.jar!/META-INF/kotlinx-datetime.kotlin_module:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
when updated some options in gradle.properties:
pluginGroup = com.yamatodaiwa
pluginName = Yamato-Daiwa Frontend
pluginVersion = 0.0.3
pluginSinceBuild = 221
pluginUntilBuild = 222.*
pluginVerifierIdeVersions = 2022.1, 2022.2
platformType = IC
platformVersion = 2022.2
platformDownloadSources = true
javaVersion = 11
gradleVersion = 7.2
kotlin.stdlib.default.dependency = false
I checked the similar topics, but the solutions like
ext.kotlin_version = '1.6.10'
are not actual for the projects with build.gradle.kts (not build.gradle) - there is no ext.kotlin_version option:
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
fun properties(key: String) = project.findProperty(key).toString()
plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.5.30"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.1.6"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "1.3.0"
// Gradle Qodana Plugin
id("org.jetbrains.qodana") version "0.1.12"
}
group = properties("pluginGroup")
version = properties("pluginVersion")
...
📄 Full code
If you need to check ano other files to answer, please check the plugin's repository.
Solution: upgrade all the used Gradle plugins to their latest versions.

java.lang.NoSuchMethodError when installing plugin in ktor

I am trying to add Resources plugin into my ktor client using the following code:
...
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.java.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.resources.*
import io.ktor.client.request.*
...
...
val HTTP_CLIENT = HttpClient(Java) {
install(Resources)
}
...
And here's part of my build.gradle.kts:
val ktor_version: String by project
plugins {
val kotlinVersion = "1.6.10"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-java:$ktor_version")
implementation("io.ktor:ktor-client-resources:$ktor_version")
}
The compile is successful, but when running I got following error:
java.lang.NoSuchMethodError: 'void io.ktor.client.HttpClientConfig.install$default(io.ktor.client.HttpClientConfig, io.ktor.client.plugins.HttpClientPlugin, kotlin.jvm.functions.Function1, int, java.lang.Object)'
2022-04-16 13:28:45 W/stderr: at NMEBoot-1.1.mirai.jar//NoMathExpectation.NMEBoot.wolframAlpha.Conversation$Companion$HTTP_CLIENT$1.invoke(Conversation.kt:20)
2022-04-16 13:28:45 W/stderr: at NMEBoot-1.1.mirai.jar//NoMathExpectation.NMEBoot.wolframAlpha.Conversation$Companion$HTTP_CLIENT$1.invoke(Conversation.kt:19)
2022-04-16 13:28:45 W/stderr: at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:41)
2022-04-16 13:28:45 W/stderr: at NMEBoot-1.1.mirai.jar//NoMathExpectation.NMEBoot.wolframAlpha.Conversation.<clinit>(Conversation.kt:19)
I checked the jar and the source code and they both did have install method, but their signature was different from the signature described in the error.
I don't know if it is my fault or something else. Could someone help me solve this problem?
Edit: Here's a simplified project: KtorInstallTest
This is a bug on the Mirai side.
Mirai Console uses Kotlin 1.6.0 and for some reasons forces all plugins to use the same version of Kotlin, causing this problem. We plan to update to 1.6.20 by Mirai 2.11.0.

'JacocoTaskExtension' does not exist with jdk11 , AGP 7.0.+ and ,Gradle 7.0.+

jacoco works like charm with AGP 4.0.1, gradle 6.+ , jdk1.8 but throw error "JacocoTaskExtension" not found with upgraded gradle version which is below.
Gradle 7.0.2
------------------------------------------------------------
Build time: 2021-05-14 12:02:31 UTC
Revision: 1ef1b260d39daacbf9357f9d8594a8a743e2152e
Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.12 (Oracle Corporation 11.0.12+8-LTS-237)
OS: Mac OS X 11.5 x86_64
Steps to reproduce :
I am not able to import JacocoTaskExtension in below kotlin class CodeCoveragePlugin
It's working fine with jkd 1.8 but not with jdk11
why am i using jdk11 ?
jdk11 is mandatory for agp 7.+ and gradle 7.+
My final goal : make it functional with agp7.+
package com.jitendra.sdk.android.gradle.quality.coverage
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
#Suppress("UnstableApiUsage")
class CodeCoveragePlugin : Plugin<Project> {
override fun apply(project: Project) = project.run {
val extension = extensions.create("codeCoverage", CodeCoverageExtension::class)
apply(plugin = "jacoco")
jacoco {
toolVersion = 0.8.7
}
java { createJavaTasks(sourceSets["main"], extension) }
setupAndroidTasks(extension)
}
private fun Project.java(run: JavaPlugin.() -> Unit) = plugins.withType(JavaPlugin::class, run)
private val Project.sourceSets get() = convention.getPlugin(JavaPluginConvention::class).sourceSets
private fun Project.jacoco(run: JacocoPluginExtension.() -> Unit) = configure(run)
}
I have had a similar issue. Could you please check the listed stack trace from the console?
If it contains:
Unexpected SMAP line: *S KotlinDebug"
Then it's clear that you haven't used the correct version 0.8.7 of Jacoco, as discussed here. In my case, I still need to add the following configuration:
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jacoco") {
useVersion("0.8.7")
}
}
}
You can put it inside your project.run closure. Hope it works. If not, please share your stack trace as part of your question.

Kotlin/Native compileKotlinIosX64 task fails when building iOS app

I have a Kotlin Multiplatform project. I recently updated to Kotlin 1.4-M2 (I need it to solve some issues with Ktor).
After updating all the required libraries, resolving all gradle issues and having my Android project compile successfully, I now encounter the following error when building the iOS app:
Task :shared:compileKotlinIosX64
e: Compilation failed: Could not find declaration for unbound symbol org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl#56f11f08
* Source files: [all shared folder kt files]
* Compiler version info: Konan: 1.4-M2 / Kotlin: 1.4.0
* Output kind: LIBRARY
e: java.lang.IllegalStateException: Could not find declaration for unbound symbol org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl#56f11f08
at org.jetbrains.kotlin.ir.util.ExternalDependenciesGeneratorKt.getDeclaration(ExternalDependenciesGenerator.kt:76)
The curious thing is that in Source files it shows all the files in the shared code folder. I checked and absolutely all kt files appear in there. So my guess is that it is some issue when building the shared code, but does not seem specific of any library.
This is a slightly reduced version of how my build.gradle.kts looks like:
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("kotlinx-serialization")
id("com.android.library")
id("io.fabric")
}
// CocoaPods requires the podspec to have a version.
version = "1.0"
tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
kotlin {
ios()
android()
cocoapods {
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion")
api("org.kodein.di:kodein-di:7.1.0-kotlin-1.4-M3-84")
implementation("io.mockk:mockk:1.9.2")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
api("com.russhwolf:multiplatform-settings:$multiplatformSettingsVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-json:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
}
}
}
}
And the library versions are as follows:
val ktorVersion = "1.3.2-1.4-M2"
val kotlinVersion = "1.4-M2"
val coroutinesVersion = "1.3.7-native-mt-1.4-M2"
val serializationVersion = "0.20.0-1.4-M2"
val multiplatformSettingsVersion = "0.6-1.4-M2"
It's worth mentioning this was building correctly in iOS when using 1.3.72.
As #KevinGalligan suggested, I updated Kotlin and all related libs to 1.4.0-rc and the problem was solved.
The root issue with 1.4-M2 remains unknown.

Kotlin MPP - Cannot resolve Stetho Interceptor

I'm trying out for the first time to build a Kotlin MPP using a Kotlin DSL gradle file.
The issue is quite simple but I've been trying everything I could think of to fix it : the android shared code can't resolve Stetho interceptor
Screenshot of the issue
My build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("kotlinx-serialization")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.14.0")
// HTTP
implementation("io.ktor:ktor-client-core:1.3.0-rc")
implementation("io.ktor:ktor-client-json:1.3.0-rc")
implementation("io.ktor:ktor-client-serialization:1.3.0-rc")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3")
implementation("io.ktor:ktor-client-android:1.3.0-rc")
implementation("io.ktor:ktor-client-json-jvm:1.3.0-rc")
implementation("io.ktor:ktor-client-serialization-jvm:1.3.0-rc")
implementation("io.ktor:ktor-client-okhttp:1.3.0-rc")
implementation("com.squareup.okhttp3:logging-interceptor:4.0.1")
implementation( "com.facebook.stetho:stetho-okhttp3:1.5.1")
}
Thanks a lot for your help !
EDIT :
So I found out that when I replace
jvm("android")
with
android()
Stetho-interceptor can be imported, but the "expected" and "actual" keyword are not correctly linked by Android studio for iOS :
"Actual property ... has no corresponding expected declaration" when I hover an actual declaration for iOS
When I use both
jvm("android")
android()
I get a gradle error :
"The target 'android' already exists, but it was not created with the 'jvm' preset. To configure it, access it by name in kotlin.targets or use the preset function 'android'."
you do not need to have jvm("android") if you already are using the android() target. if you want a separate jvm target then you should name it something different (ex. jvm("something") ).
Once you add your android target and manifest + android definitions, the libraries should resolve. the facebook library likely depends on an android target which is why it is not resolving.