Skip to content

Commit b021757

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
[Plugin] Replace deprecated VersionNumber with stdlib KotlinVersion
1 parent b3b6609 commit b021757

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
@@ -85,3 +81,13 @@ class BenchmarksPlugin : Plugin<Project> {
8581
}
8682
}
8783
}
84+
85+
private fun Project.getKotlinVersion(): KotlinVersion {
86+
val kotlinVersion = getKotlinPluginVersion()
87+
val (major, minor) = kotlinVersion
88+
.split('.')
89+
.take(2)
90+
.map { it.toInt() }
91+
val patch = kotlinVersion.substringAfterLast('.').substringBefore('-').toInt()
92+
return KotlinVersion(major, minor, patch)
93+
}

0 commit comments

Comments
 (0)