how can I include (and call) a kotlin library as d...
# kotlin-native
e
how can I include (and call) a kotlin library as dependency? Simply adding it to
build.gradle
as usual? Will then it be compiled/added together at the
gradlew build
? (Sorry, but I can't test at the moment)
i
You can add
*.kt.bc
library built by Kotlin/Native compiler using the
library()
DSL method.
Copy code
konanArtifacts {
    foo {
        library 'path/to/.kt.bc'
        libraries 'path/1', 'path/2'
    }
}
If you have a library in the same project you may link it with an executable using the
artifactPath
property of a compilation task and setting dependencies between the tasks manually. As you can see this way is a bit complicated so we are going to simplify it in the future releases.
Copy code
konanArtifacts {
    // This is a library
    foo {
        inputFiles project.file('foo.kt')
        noLink()
    }

    // This is an executable.
    bar {
        inputFiles project.file('bar.kt')
        library project.files(konanArtifacts['foo'].compilationTask.artifactPath)
    }

}

konanArtifacts['bar'].compilationTask.dependsOn(konanArtifacts['foo'].compilationTask)
e
wait, I meant traditional kotlin, not-native
o
Kotlin/Native is a backend on its own, Kotlin/JVM is different one, so if your code in in pure Kotlin - you could reuse your code, generic JVM code is not suitable here
e
uhm so basically if I double check to not have any jvm imports, how could I include it?
o
just create library from your sources and do as Ilya suggested above
e
ok, I'll try