My script can't resolve references for `io` depend...
# scripting
d
My script can't resolve references for
io
dependencies, no ideia why. I'll post my code + the error in the thread.
Code:
Copy code
#!/usr/bin/env kotlin

@file:Repository("<https://repo1.maven.org/maven2/>")

@file:DependsOn("io.ktor:ktor-client-core:2.3.12")
@file:DependsOn("io.ktor:ktor-client-cio:2.3.12")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")

import kotlinx.coroutines.*
import io.ktor.client.*

GlobalScope.launch {
  val client = HttpClient(CIO)
  val response: HttpResponse = client.get("<https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s>")
  println("Response status: ${response.status}")
  client.close()
}
Error:
Copy code
test.main.kts:10:8: error: unresolved reference 'io'.
import io.ktor.client.*
I've checked the Maven Central of Ktor to verify which repo is stored in, and everything seems correct in my code 🙂 It can find the import for coroutines though...
for multiplatform libraries (that haven't hacked their maven metadata the way kotlinx.coroutines has) you need to directly use the JVM artifact, e.g.
Copy code
@file:DependsOn("io.ktor:ktor-client-core-jvm:2.3.12")
@file:DependsOn("io.ktor:ktor-client-cio-jvm:2.3.12")
because the maven resolver isn't smart enough
d
Oh, at least there's a way to "force" it to work. Never would've guessed what was the problem. Thanks for helping out, I really appreciate it!