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

Move the logic from koltin repo atomicfu gradle plugin to the gradle plugin in the library. #406

Merged
merged 18 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,48 +89,13 @@ private fun Project.applyAtomicfuCompilerPlugin() {
// are published as `kotlin-atomicfu-compiler-plugin-embeddable` since Kotlin 1.9.0 and may be accessed out of the Kotlin repo.
plugins.apply(AtomicfuKotlinCompilerPluginInternal::class.java)
} else {
// for KGP >= 1.7.20:
// compiler plugin for JS IR is applied via the property `kotlinx.atomicfu.enableJsIrTransformation`
// compiler plugin for JVM IR is applied via the property `kotlinx.atomicfu.enableJvmIrTransformation`
if (kotlinVersion.atLeast(1, 7, 20)) {
// Check that the project has `org.jetbrains.kotlin:atomicfu` in the classpath, otherwise throw an error.
val isAtomicfuCompilerPluginOnTheClasspath = project.buildscript.configurations.findByName("classpath")
?.allDependencies?.any { it.group == "org.jetbrains.kotlin" && it.name == "atomicfu" && it.version == getKotlinPluginVersion()}
if (isAtomicfuCompilerPluginOnTheClasspath == false) {
error("You are applying `kotlinx-atomicfu` plugin of version 0.23.3 or newer.\n" +
"If you wish to use this version of the plugin with Kotlin version lower than 1.9.0, you must manually include `org.jetbrains.kotlin:atomicfu:${getKotlinPluginVersion()}` in your buildscript. \n" +
"Here's how you can do it: \n" +
"```\n" +
"buildscript {\n" +
" dependencies {\n" +
" classpath(\"org.jetbrains.kotlin:atomicfu:${getKotlinPluginVersion()}\")\n" +
" }\n" +
"}\n" +
"```\n" +
"Alternatively, you can upgrade your Kotlin version to 1.9.0 or newer.\n"
)
}
plugins.apply(AtomicfuKotlinGradleSubplugin::class.java)
extensions.getByType(AtomicfuKotlinGradleSubplugin.AtomicfuKotlinGradleExtension::class.java).apply {
isJsIrTransformationEnabled = rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION)
isJvmIrTransformationEnabled = rootProject.getBooleanProperty(ENABLE_JVM_IR_TRANSFORMATION)
if (kotlinVersion.atLeast(1, 9, 20)) {
// Native IR transformation is available since Kotlin 1.9.20
isNativeIrTransformationEnabled = rootProject.getBooleanProperty(ENABLE_NATIVE_IR_TRANSFORMATION)
}
}
} else {
// for KGP >= 1.6.20 && KGP <= 1.7.20:
// compiler plugin for JS IR is applied via the property `kotlinx.atomicfu.enableIrTransformation`
// compiler plugin for JVM IR is not supported yet
if (kotlinVersion.atLeast(1, 6, 20)) {
if (rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION_LEGACY)) {
plugins.apply(AtomicfuKotlinGradleSubplugin::class.java)
}
}
}
error("You are applying `kotlinx-atomicfu` plugin of version 0.23.3 or newer. " +
Copy link
Collaborator Author

@mvicsokolova mvicsokolova Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, in case of KGP version < 1.9.0, I asked users to add org.jetbrains.kotlin:atomicfu dependency manually to the buildscript. However, this caused further problems, that already were solved in higher Kotlin versions.

E.g. the problem below would occur if you try to apply the current kotlinx-atomicfu version with Kotlin 1.8.20 and just add the kotlin:atomicfu:1.8.20 dependency manually (this problem was solved in 0.23.0 and Kotlin 1.9.10)

e: Could not find ".gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-linuxarm64/0.23.2/7b4270560c2723dc55b1d3c8925b7b93201c437b/atomicfu.klib" in [IdeaProjects/kotlinx-atomicfu-new/integration-testing/examples/mpp-sample, .konan/klib, .konan/kotlin-native-prebuilt-macos-aarch64-1.8.20/klib/common, .konan/kotlin-native-prebuilt-macos-aarch64-1.8.20/klib/platform/linux_arm64]

So, I decided to write this error message about incompatibility instead.
I've checked that the sample mpp project can be built with kotlinx-atomicfu 0.22.0 and Kotlin down to 1.6.0, though I believe these are very marginal use cases.

@fzhinkin WDYT? 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version 0.23.3 or newer

Can we print the exact version here?

I think it should be enough to:

  • mention that Kotlin version should be upgraded
  • add a document (like readme) describing an alternative solution for those who can't upgrade the Kotlin for some reason

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a note about downgrading atomicfu version as an alternative solution in the README. And in the message left just the recommendation to upgrade the Kotlin version.

"However, this version of the plugin is only compatible with Kotlin versions newer than 1.9.0.\n" +
"If you wish to use this version of the plugin, please upgrade your Kotlin version to 1.9.0 or newer.\n" +
"The alternative solution is to downgrade `kotlinx-atomicfu` plugin version to 0.22.0.\n" +
"Please note, that using the latest version of the plugin and upgrading the Kotlin version is a more preferable option.\n\n" +
"If you encounter any problems, please submit the issue: https://github.com/Kotlin/kotlinx-atomicfu/")
fzhinkin marked this conversation as resolved.
Show resolved Hide resolved
}

}

private fun Project.configureDependencies() {
Expand Down