summaryrefslogtreecommitdiff
path: root/buildSrc/src/main/kotlin/KotlinVersion.kt
blob: 5ac051ecad44b4b6f2ec9f795d1d7abe8ca2f72a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@file:JvmName("KotlinVersion")

fun isKotlinVersionAtLeast(kotlinVersion: String, atLeastMajor: Int, atLeastMinor: Int, atLeastPatch: Int): Boolean {
    val (major, minor) = kotlinVersion
        .split('.')
        .take(2)
        .map { it.toInt() }
    val patch = kotlinVersion.substringAfterLast('.').substringBefore('-').toInt()
    return when {
        major > atLeastMajor -> true
        major < atLeastMajor -> false
        else -> (minor == atLeastMinor && patch >= atLeastPatch) || minor > atLeastMinor
    }
}