Warren MacEvoy
Warren MacEvoy

Reputation: 979

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?

Upvotes: 13

Views: 6299

Answers (1)

Cililing
Cililing

Reputation: 4753

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.

Upvotes: 27

Related Questions