I am new to k/n. Why are there two gradle plugins ...
# kotlin-native
c
I am new to k/n. Why are there two gradle plugins (https://kotlinlang.org/docs/reference/native/gradle_plugin.html and https://kotlinlang.org/docs/tutorials/native/gradle-for-kotlin-native.html)? Does it mean one of them will be deprecated in the future? Also, how about the kotlin-dsl support of them?
s
The second link is to an older deprecated plugin. The first one you will want to use if you are creating a native only project. If you want to share code between native, jvm, and js then you should use the multiplatform gradle plugin.
c
Got it. Thanks.
n
The older plugin isn't deprecated yet and does have some advantages over the new one with better documentation, Gradle Kotlin DSL support, and is more mature.
c
In the first link, the plugin
org.jetbrains.kotlin.platform.native
is used. But when I check it in https://plugins.gradle.org/, it says “The plugin is intended for native parts of multiplatform projects.“. Confused.
Found the other one:
org.jetbrains.kotlin.native
. Guess this is the one to use when multiplatform isn’t needed. Correct?
m
Even if multiplatform isn’t needed better use multiplatform plugin - it's supported in IDEA and CLion.
👍 2
s
I had trouble with the mpp plugin while trying to setup a project that was wrapping a c library. I didn’t need anything in
common
but needed to have a
darwin
sourceset that the iOS and macOS targets could depend on. The project would compile but IntelliJ complained about not being able to import Kotlin standard lib stuff and my c library on any source file in the Darwin folder. I gave up on the mpp plugin and just went with the newer native plugin. The syntax is similar and while it doesn’t work well in IntelliJ, it’s good enough to code with.
c
At the end I chose the konan plugin. Simpler and easier. And there is an example of kotlin-dsl version to start with (https://github.com/JetBrains/kotlin-native/tree/master/samples/weather_function). I update the konan version to
1.3.10
. But it only works with gradle
4.9
or below. Gradle
4.10.x
with konan
1.3.10
produces errors:
Copy code
Script compilation errors:

  Line 09:     interop("curl") {
               ^ Overload resolution ambiguity: 
                   public final fun interop(name: String, configureAction: Action<KonanInteropLibrary>): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer
                   public final fun interop(name: String, configureAction: KonanInteropLibrary.() -> Unit): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer

  Line 10:         defFile("curl.def")
                   ^ Unresolved reference: defFile

  Line 13:     interop("cjson") {
               ^ Overload resolution ambiguity: 
                   public final fun interop(name: String, configureAction: Action<KonanInteropLibrary>): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer
                   public final fun interop(name: String, configureAction: KonanInteropLibrary.() -> Unit): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer

  Line 14:         defFile("cjson.def")
                   ^ Unresolved reference: defFile

  Line 17:     program("weather") {
               ^ Overload resolution ambiguity: 
                   public final fun program(name: String, configureAction: Action<KonanProgram>): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer
                   public final fun program(name: String, configureAction: KonanProgram.() -> Unit): Unit defined in org.jetbrains.kotlin.gradle.plugin.konan.KonanArtifactContainer

  Line 18:         entryPoint("org.example.weather_func.main")
                   ^ Unresolved reference: entryPoint

  Line 19:         libraries {
                   ^ Unresolved reference: libraries

  Line 20:             artifact("cjson")
                       ^ Unresolved reference: artifact

  Line 21:             artifact("curl")
                       ^ Unresolved reference: artifact

9 errors
m
konan
is deprecated.