Skip to content

Commit 648f55c

Browse files
author
Abduqodiri Qurbonzoda
committed
[Plugin] Replace deprecated VersionNumber with stdlib KotlinVersion
1 parent 126c003 commit 648f55c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

plugin/main/src/kotlinx/benchmark/gradle/BenchmarksPlugin.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ class BenchmarksPlugin : Plugin<Project> {
3535
return // TODO: Do we need to fail build at this point or just ignore benchmarks?
3636
}
3737

38-
val kotlinClass = tryGetClass<KotlinBasePluginWrapper>("org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper")
39-
if (kotlinClass != null) {
40-
plugins.findPlugin(kotlinClass)?.run {
41-
logger.info("Detected Kotlin plugin version '${project.getKotlinPluginVersion()}'")
42-
if (VersionNumber.parse(project.getKotlinPluginVersion()) < VersionNumber(1, 7, 20, null))
43-
logger.error("JetBrains Gradle Benchmarks plugin requires Kotlin version 1.7.20 or higher")
44-
}
38+
logger.info("Detected Kotlin plugin version '${project.getKotlinPluginVersion()}'")
39+
if (!getKotlinVersion().isAtLeast(1, 7, 20)) {
40+
logger.error("JetBrains Gradle Benchmarks plugin requires Kotlin version 1.7.20 or higher")
4541
}
4642

4743
// Create empty task that will depend on all benchmark building tasks to build all benchmarks in a project
@@ -84,3 +80,13 @@ class BenchmarksPlugin : Plugin<Project> {
8480
}
8581
}
8682
}
83+
84+
private fun Project.getKotlinVersion(): KotlinVersion {
85+
val kotlinVersion = getKotlinPluginVersion()
86+
val (major, minor) = kotlinVersion
87+
.split('.')
88+
.take(2)
89+
.map { it.toInt() }
90+
val patch = kotlinVersion.substringAfterLast('.').substringBefore('-').toInt()
91+
return KotlinVersion(major, minor, patch)
92+
}

0 commit comments

Comments
 (0)