Reputation: 93
I'm trying to build a Kotlin Multiplatform command line application targeting linuxX64 in a first step. Therefore I wanted to build a client based on Ktor which is used in the common module.
Version overview
build.gradle.kts
plugins {
kotlin("multiplatform") version "1.3.31"
}
repositories {
mavenCentral()
maven { url = uri("https://kotlin.bintray.com/ktor") }
}
kotlin {
linuxX64("linux") {
binaries {
executable()
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
api("io.ktor:ktor-client-core:1.1.5")
}
}
val linuxMain by getting {
dependsOn(commonMain)
dependencies {
api("io.ktor:ktor-client-curl:1.1.5")
}
}
}
}
src/linuxMain/kotlin/Main.kt
fun main(){
val client = MyClient()
client.execute()
}
src/commonMain/kotlin/MyClient.kt
import io.ktor.client.*
class MyClient {
private val client = HttpClient()
fun execute() {
//do something with Ktor client
}
}
When I build the project I get the following build issue:
11:15:21: Executing task 'build'...
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :wrapper
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :compileKotlinLinux FAILED
e: .../src/commonMain/kotlin/MyClient.kt: (1, 8): Unresolved reference: io
e: .../src/commonMain/kotlin/MyClient.kt: (5, 26): Unresolved reference: HttpClient
I'm new to Kotlin Native/Mutliplatform and Ktor. So bear with me if this my setup is wrong...
Upvotes: 3
Views: 7381
Reputation: 93
Adding enableFeaturePreview("GRADLE_METADATA")
to settings.gradle.kts fixed the build issue.
I just made a successful HTTP call with a linuxX64 binary using ktor-client-curl :-)
Upvotes: 4