Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine version of Kotlin at runtime

What can be written to determine the version of Kotlin at runtime?

fun main(args : Array<String>) { 
  println("v" + System.getProperty("java.version"))
}

prints a version, but it is the Java JDK version. Using "kotlin.version" prints null. Can this be done at runtime?

If the general answer is no, is there a way to embed this information from the compile phase into a particular function or class?

like image 779
Warren MacEvoy Avatar asked Oct 09 '18 02:10

Warren MacEvoy


People also ask

Does Kotlin have a runtime?

Kotlin includes its own standard class library (the Kotlin runtime), separate to the Java class library. To distribute a jar file that can be run by anyone with a plain old JRE, you need to bundle the Kotlin runtime as well.

How do I change my Kotlin Android version?

In your Android studio, Go to Tools -> Kotlin -> Configure Kotlin Updates. Save this answer.

What is Kotlin latest version?

1.7.20 / 29 September 2022. Typing discipline. Inferred, static, strong. Platform. Android.

What is Kotlin compiler?

The Kotlin compiler for JVM compiles Kotlin source files into Java class files. The command-line tools for Kotlin to JVM compilation are kotlinc and kotlinc-jvm . You can also use them for executing Kotlin script files. In addition to the common options, Kotlin/JVM compiler has the options listed below.


1 Answers

Use kotlin.KotlinVersion.CURRENT:

fun main(args: Array<String>) {
    println(KotlinVersion.CURRENT)
}

Try it out here by changing the version in the bottom-right corner of the page.

like image 138
Cililing Avatar answered Sep 21 '22 13:09

Cililing