@@ -34,7 +34,7 @@ open class AtomicFUGradlePlugin : Plugin<Project> {
34
34
val pluginVersion = rootProject.buildscript.configurations.findByName(" classpath" )
35
35
?.allDependencies?.find { it.name == " atomicfu-gradle-plugin" }?.version
36
36
extensions.add(EXTENSION_NAME , AtomicFUPluginExtension (pluginVersion))
37
- if (rootProject.getBooleanProperty(ENABLE_IR_TRANSFORMATION )) {
37
+ if (rootProject.getBooleanProperty(ENABLE_IR_TRANSFORMATION ) && isCompilerPluginAvailable() ) {
38
38
plugins.apply (AtomicfuKotlinGradleSubplugin ::class .java)
39
39
}
40
40
configureDependencies()
@@ -86,6 +86,15 @@ private fun Project.configureTasks() {
86
86
}
87
87
}
88
88
89
+ private fun Project.isCompilerPluginAvailable (): Boolean {
90
+ // kotlinx-atomicfu compiler plugin is available for KGP >= 1.6.20
91
+ val (majorVersion, minorVersion, patch) = getKotlinPluginVersion()
92
+ .split(' .' )
93
+ .take(3 )
94
+ .map { it.toInt() }
95
+ return majorVersion == 1 && (minorVersion == 6 && patch >= 20 || minorVersion > 6 )
96
+ }
97
+
89
98
private fun Project.getBooleanProperty (name : String ) =
90
99
rootProject.findProperty(name)?.toString()?.toBooleanStrict() ? : false
91
100
@@ -101,15 +110,15 @@ private fun Project.needsJsIrTransformation(target: KotlinTarget): Boolean =
101
110
private fun KotlinTarget.isJsIrTarget () = (this is KotlinJsTarget && this .irTarget != null ) || this is KotlinJsIrTarget
102
111
103
112
private fun Project.addCompilerPluginDependency () {
104
- val kotlinVersion = rootProject.buildscript.configurations.findByName( " classpath " )
105
- ?.allDependencies?.find { it.name == " kotlin-gradle-plugin " }?.version
106
- withKotlinTargets { target ->
107
- if (needsJsIrTransformation( target)) {
108
- target.compilations.forEach { kotlinCompilation ->
109
- kotlinCompilation.dependencies {
110
- // add atomicfu compiler plugin dependency
111
- // to provide the `kotlinx- atomicfu-runtime` library used during compiler plugin transformation
112
- compileOnly( " org.jetbrains.kotlin:atomicfu: $kotlinVersion " )
113
+ if (isCompilerPluginAvailable()) {
114
+ withKotlinTargets { target ->
115
+ if (needsJsIrTransformation( target)) {
116
+ target.compilations.forEach { kotlinCompilation ->
117
+ kotlinCompilation.dependencies {
118
+ // add atomicfu compiler plugin dependency
119
+ // to provide the `kotlinx- atomicfu-runtime` library used during compiler plugin transformation
120
+ compileOnly( " org.jetbrains.kotlin: atomicfu: ${getKotlinPluginVersion()} " )
121
+ }
113
122
}
114
123
}
115
124
}
0 commit comments