Skip to content

Commit c41d50a

Browse files
committed
Added versions compatibility check (gradle >= 7.0, KGP >= 1.7.0)
1 parent 76c9d13 commit c41d50a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.gradle.api.tasks.*
1515
import org.gradle.api.tasks.compile.*
1616
import org.gradle.api.tasks.testing.*
1717
import org.gradle.jvm.tasks.*
18+
import org.gradle.util.*
1819
import org.jetbrains.kotlin.gradle.dsl.*
1920
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
2021
import org.jetbrains.kotlin.gradle.plugin.*
@@ -37,9 +38,12 @@ private const val TEST_IMPLEMENTATION_CONFIGURATION = "testImplementation"
3738
private const val ENABLE_JS_IR_TRANSFORMATION_LEGACY = "kotlinx.atomicfu.enableIrTransformation"
3839
private const val ENABLE_JS_IR_TRANSFORMATION = "kotlinx.atomicfu.enableJsIrTransformation"
3940
private const val ENABLE_JVM_IR_TRANSFORMATION = "kotlinx.atomicfu.enableJvmIrTransformation"
41+
private const val MIN_SUPPORTED_GRADLE_VERSION = "7.0"
42+
private const val MIN_SUPPORTED_KGP_VERSION = "1.7.0"
4043

4144
open class AtomicFUGradlePlugin : Plugin<Project> {
4245
override fun apply(project: Project) = project.run {
46+
checkCompatibility()
4347
val pluginVersion = rootProject.buildscript.configurations.findByName("classpath")
4448
?.allDependencies?.find { it.name == "atomicfu-gradle-plugin" }?.version
4549
extensions.add(EXTENSION_NAME, AtomicFUPluginExtension(pluginVersion))
@@ -49,6 +53,24 @@ open class AtomicFUGradlePlugin : Plugin<Project> {
4953
}
5054
}
5155

56+
private fun Project.checkCompatibility() {
57+
val currentGradleVersion = GradleVersion.current()
58+
val kotlinVersion = getKotlinVersion()
59+
val minSupportedVersion = GradleVersion.version(MIN_SUPPORTED_GRADLE_VERSION)
60+
if (currentGradleVersion < minSupportedVersion) {
61+
throw GradleException(
62+
"The current Gradle version is not compatible with Atomicfu gradle plugin. " +
63+
"Please use Gradle $MIN_SUPPORTED_GRADLE_VERSION or newer, or the previous version of Atomicfu gradle plugin."
64+
)
65+
}
66+
if (!kotlinVersion.atLeast(1, 7, 0)) {
67+
throw GradleException(
68+
"The current Kotlin gradle plugin version is not compatible with Atomicfu gradle plugin. " +
69+
"Please use Kotlin $MIN_SUPPORTED_KGP_VERSION or newer, or the previous version of Atomicfu gradle plugin."
70+
)
71+
}
72+
}
73+
5274
private fun Project.configureDependencies() {
5375
withPluginWhenEvaluatedDependencies("kotlin") { version ->
5476
dependencies.add(

0 commit comments

Comments
 (0)