I am programming in Kotlin and I want to use skiko for my Kotlin/Native application. My Gradle build file is exactly as in the skiko's README (see below), but for some reason I get an error: "Unresolved reference: implementation" What could this possibly mean? I thought this is part of Kotlin's DSL? So how can it not know this function? I have never had this problem in other projects.
Thanks in advance
I use Gradle 8.10 and I'm only syncing Gradle changes in IntelliJ. From looking at the setting "Build and run using: Gradle" I don't think IntelliJ is using Gradle Wrapper.
I tried copying build files from other projects and also doing grade init myself
the build.gradle.kts
from the repo is
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
val osName = System.getProperty("os.name")
val targetOs = when {
osName == "Mac OS X" -> "macos"
osName.startsWith("Win") -> "windows"
osName.startsWith("Linux") -> "linux"
else -> error("Unsupported OS: $osName")
}
val osArch = System.getProperty("os.arch")
val targetArch = when (osArch) {
"x86_64", "amd64" -> "x64"
"aarch64" -> "arm64"
else -> error("Unsupported arch: $osArch")
}
val version = "0.8.9" // or any more recent version
val target = "${targetOs}-${targetArch}"
dependencies {
implementation("org.jetbrains.skiko:skiko-awt-runtime-$target:$version")
}
The setup instructions you have linked specifically show an excerpt from a setup for a Kotlin JVM project (which we know because the implementation
configuration is specific to JVM projects). Moreover, because JVMs can run on a wide variety of underlying platforms, the script needs to work out what the current platform is.
None of this is necessary for a Kotlin/Native application because the type of the platform in use is known by Gradle at build time. This means that Gradle can use variant-aware dependency selection to pick up the correct dependency for the platform without any of the introspection of the platform shown. This also means we can just add the umbrella Skiko multiplatform module as a dependency of the commonMain
source set and keeps things simple (and flexible if we decide to target other Kotlin/Native platforms).
This means your build script can simply be:
plugins {
kotlin("multiplatform") version "2.1.0"
}
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
kotlin {
val skikoVersion = "0.8.9"
// We must choose a target platform. See https://kotlinlang.org/docs/multiplatform-discover-project.html#targets
// Available targets: https://kotlinlang.org/docs/native-target-support.html
macosArm64() // Let's choose MacOS on Apple silicon for example
// We can then select dependencies using the multiplatform pattern
// See https://kotlinlang.org/docs/multiplatform-add-dependencies.html#dependency-on-a-kotlin-library
sourceSets {
commonMain {
dependencies {
implementation("org.jetbrains.skiko:skiko:$skikoVersion")
}
}
}
}
Note this shows the Kotlin multiplatform plugin being applied; the application of a Kotlin plugin is omitted from the sample setup you supplied.
I think it's fair to say that the guidance provided for the module could be more helpful. You might consider raising a GitHub issue and asking them to expand it to be more helpful for those less familiar with Kotlin multiplatform setups.