Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply atomicfu compiler plugin directly in buildscript classpath. #377

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ operations. They can be also atomically modified via `+=` and `-=` operators.

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

In top-level build file:
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).

> Note: kotlinx-atomicfu gradle plugin does not have an id and is not currently published to the Gradle Plugin Portal.
> Therefore, the only available method for application is through the buildscript specification.

<details open>
<summary>Kotlin</summary>
<summary>Kotlin DSL</summary>

```kotlin
buildscript {
Expand All @@ -120,6 +125,9 @@ buildscript {

dependencies {
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.23.1")
// Please note that the Kotlin version specified for the atomicfu compiler plugin
// should match the Kotlin version used in your project.
classpath("org.jetbrains.kotlin:atomicfu:$kotlin_version")
}
}

Expand All @@ -128,7 +136,7 @@ apply(plugin = "kotlinx-atomicfu")
</details>

<details>
<summary>Groovy</summary>
<summary>Groovy DSL</summary>

```groovy
buildscript {
Expand All @@ -137,6 +145,9 @@ buildscript {
}
dependencies {
classpath 'org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.23.1'
// Please note that the Kotlin version specified for the atomicfu compiler plugin
// should match the Kotlin version used in your project.
classpath 'org.jetbrains.kotlin:atomicfu:$kotlin_version'
}
}

Expand Down
2 changes: 1 addition & 1 deletion atomicfu-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Atomicfu compiler plugin dependency will be loaded to kotlinCompilerPluginClasspath
// Atomicfu plugin will only be applied if the flag is set kotlinx.atomicfu.enableJsIrTransformation=true
implementation "org.jetbrains.kotlin:atomicfu:$kotlin_version"
compileOnly "org.jetbrains.kotlin:atomicfu:$kotlin_version"

testImplementation gradleTestKit()
testImplementation 'org.jetbrains.kotlin:kotlin-test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,42 @@ open class AtomicFUGradlePlugin : Plugin<Project> {
val pluginVersion = rootProject.buildscript.configurations.findByName("classpath")
?.allDependencies?.find { it.name == "atomicfu-gradle-plugin" }?.version
extensions.add(EXTENSION_NAME, AtomicFUPluginExtension(pluginVersion))
checkClasspathForAtomicfuCompilerPlugin(pluginVersion)
applyAtomicfuCompilerPlugin()
configureDependencies()
configureTasks()
}
}

private fun Project.checkClasspathForAtomicfuCompilerPlugin(pluginVersion: String?) {
val kotlinVersion = getKotlinPluginVersion()
rootProject.buildscript.configurations.findByName("classpath")
?.allDependencies?.find { it.group == "org.jetbrains.kotlin" && it.name == "atomicfu" }?.let {
require(it.version == kotlinVersion) {
"Please ensure that the Kotlin version specified for the atomicfu compiler plugin matches the Kotlin version used in your project. \n" +
"You should use this dependency in your classpath: classpath(\"org.jetbrains.kotlin:atomicfu:$kotlinVersion\")\n\n" +
"For details about plugin application, please refer to the README section at: https://github.com/Kotlin/kotlinx-atomicfu/blob/master/README.md#apply-plugin"
}
}
?: error("Please add a dependency to the atomicfu compiler plugin in the buildscript classpath configuration, " +
fzhinkin marked this conversation as resolved.
Show resolved Hide resolved
"in addition to the atomicfu-gradle-plugin dependency:\n" +
"```\n" +
"buildscript {\n" +
" repositories {\n" +
" mavenCentral() \n" +
" }\n" +
"\n" +
" dependencies {\n" +
" classpath(\"org.jetbrains.kotlinx:atomicfu-gradle-plugin:$pluginVersion\")\n" +
" classpath(\"org.jetbrains.kotlin:atomicfu:$kotlinVersion\")\n" +
" }\n" +
"}\n\n" +
"apply(plugin = \"kotlinx-atomicfu\")\n" +
"```\n\n" +
"For details about plugin application, please refer to the README section at: https://github.com/Kotlin/kotlinx-atomicfu/blob/master/README.md#apply-plugin"
)
}

private fun Project.checkCompatibility() {
val currentGradleVersion = GradleVersion.current()
val kotlinVersion = getKotlinVersion()
Expand Down Expand Up @@ -204,8 +234,6 @@ private fun Project.addJsCompilerPluginRuntimeDependency() {
if (getKotlinVersion().atLeast(1, 7, 10)) {
// since Kotlin 1.7.10 `kotlinx-atomicfu-runtime` is published and should be added directly
implementation("org.jetbrains.kotlin:kotlinx-atomicfu-runtime:${getKotlinPluginVersion()}")
} else {
implementation("org.jetbrains.kotlin:atomicfu:${getKotlinPluginVersion()}")
}
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading