Skip to content

Commit 15e8f0f

Browse files
authored
Simplify min Kotlin version check (#1839)
1 parent 406eedf commit 15e8f0f

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowKmpPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.jengelman.gradle.plugins.shadow
22

3-
import com.github.jengelman.gradle.plugins.shadow.internal.isAtLeastKgpVersion
3+
import com.github.jengelman.gradle.plugins.shadow.internal.isAtLeastKgp
44
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.SHADOW_JAR_TASK_NAME
55
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.registerShadowJarCommon
66
import org.gradle.api.Plugin
@@ -36,7 +36,7 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
3636
},
3737
)
3838

39-
if (!isAtLeastKgpVersion(1, 9, 0)) return@registerShadowJarCommon
39+
if (!isAtLeastKgp("1.9.0")) return@registerShadowJarCommon
4040

4141
@OptIn(ExperimentalKotlinGradlePluginApi::class)
4242
target.mainRun {

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/KotlinCompat.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
55

66
internal const val KOTLIN_MULTIPLATFORM_PLUGIN_ID = "org.jetbrains.kotlin.multiplatform"
77

8-
internal fun Project.isAtLeastKgpVersion(
9-
major: Int,
10-
minor: Int,
11-
patch: Int,
8+
internal fun Project.isAtLeastKgp(
9+
version: String,
1210
id: String = KOTLIN_MULTIPLATFORM_PLUGIN_ID,
1311
): Boolean {
14-
val plugin = plugins.getPlugin(id) as KotlinBasePlugin
15-
val elements = plugin.pluginVersion.takeWhile { it != '-' }.split(".")
16-
val kgpMajor = elements[0].toInt()
17-
val kgpMinor = elements[1].toInt()
18-
val kgpPatch = elements[2].toInt()
19-
return kgpMajor > major || (kgpMajor == major && (kgpMinor > minor || (kgpMinor == minor && kgpPatch >= patch)))
12+
val (major, minor, patch) = version.normalizeVersion()
13+
val (actualMajor, actualMinor, actualPatch) = (plugins.getPlugin(id) as KotlinBasePlugin).pluginVersion.normalizeVersion()
14+
return KotlinVersion(actualMajor, actualMinor, actualPatch) >= KotlinVersion(major, minor, patch)
15+
}
16+
17+
private fun String.normalizeVersion(): Triple<Int, Int, Int> {
18+
val (major, minor, patch) = takeWhile { it != '-' }.split(".").map { it.toInt() }
19+
return Triple(major, minor, patch)
2020
}

0 commit comments

Comments
 (0)