I have an android library that I distribute as a jar file; Currently it has zero dependencies (other than the things built into Java itself). I like the idea of porting it to kotlin, however I haven't been able to figure out how to do this without forcing a dependency on kotlin-stdlib
(or kotlin-stdlib-jre7
, etc)
I'm somewhat wary about doing this, because kotlin-stdlib gets updates very frequently (multiple times per month sometimes) and I don't want to cause a future compatibility problem.
Obviously if I use any of the kotlin specific functions or types (e.g. listOf
, mapOf
, etc) then of course I'd need the stdlib, but if I stick to pure java types and functions, then is this possible? And if so, how?
I am not sure this is what you are looking for but I was able to build and run run this simple program using IntelliJ Idea 2018.3
fun main() {
System.out.println("hello world")
}
and the following build.gradle file
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
apply plugin: 'application'
mainClassName = "MainKt"
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
The only thing I saw in the jar file, other than a META-INF folder was my MainKt.class I was able to run this on the jvm using
java -classpath simple.jar MainKt
I think if you don't include the standard library you cant even use Kotlin's println
function, so you have to resort to java's System.out.println
method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With