Skip to content

Commit

Permalink
Added the test and the warning message about the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mvicsokolova committed Dec 19, 2023
1 parent f362576 commit 8896e4d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ operations. They can be also atomically modified via `+=` and `-=` operators.

Gradle configuration is supported for all platforms, minimal version is Gradle 6.8.

**PLEASE NOTE!**

Application of the atomicfu-gradle-plugin now requires manual addition of the compiler plugin dependency, please follow the instructions below.

To apply kotlinx-atomicfu plugin, you need to add 2 dependencies to the project classpath:
1. `atomicfu-gradle-plugin`: it provides the necessary library dependencies and manages transformation modes.
2. `atomicfu` compiler plugin: the compiler plugin is used to perform IR transformations (see [Atomicfu compiler plugin](#atomicfu-compiler-plugin) section).
Expand Down Expand Up @@ -155,6 +159,60 @@ apply plugin: 'kotlinx-atomicfu'
```
</details>

----
**WARNING:**
In case you got a compilation error after plugin application:
```
error: unresolved reference: kotlinx
import kotlinx.atomicfu.*
^
```

and you apply `kotlin-gradle-plugin` in an old manner via the `buildscript` like below:

```groovy
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlinVersion.get()}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}")
classpath("org.jetbrains.kotlin:atomicfu:${libs.versions.kotlinVersion.get()}")
}
}
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'kotlinx-atomicfu'
```

Then this is what you can do to fix the compilation error:
1. Apply kotlin-gradle-plugin by it's id:
- remove kotlin-gradle-plugin from the classpath
- replace `apply plugin: 'org.jetbrains.kotlin.multiplatform'` with

`plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.9.21'
}`

2. Or you can also swap the dependencies to `atomicfu-gradle-plugin` and `kotlin-gradle-plugin` in the classpath:
```groovy
buildscript {
....
dependencies {
// Swap dependencies to atomicfu-gradle-plugin and kotlin-gradle-plugin
// atomicfu-gradle-plugin should go first
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlinVersion.get()}")
classpath("org.jetbrains.kotlin:atomicfu:${libs.versions.kotlinVersion.get()}")
}
}
```
----

#### Maven configuration

Maven configuration is supported for JVM projects.
Expand Down
4 changes: 4 additions & 0 deletions integration-testing/examples/plugin-order-bug/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ buildscript {
}

apply plugin: 'org.jetbrains.kotlin.multiplatform'
// The issue is described in #384. Application of kotlin-gradle-plugin by id fixes the compilation error.
//plugins {
// id 'org.jetbrains.kotlin.multiplatform' version '1.9.21'
//}
apply plugin: 'kotlinx-atomicfu'

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kotlinx.atomicfu.gradle.plugin.test.cases

import kotlinx.atomicfu.gradle.plugin.test.framework.runner.*
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.GradleBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.cleanAndBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.createGradleBuildFromSources
import kotlin.test.*

/**
* This test reproduces and tracks the issue #384.
*/
class PluginOrderBugTest {
private val pluginOrderBugProject: GradleBuild = createGradleBuildFromSources("plugin-order-bug")

@Test
fun testUserProjectBuild() {
val e = assertFailsWith<IllegalArgumentException> {
pluginOrderBugProject.cleanAndBuild()
}
check(e.message?.contains("unresolved reference: kotlinx") == true)
}
}

0 comments on commit 8896e4d

Please sign in to comment.