-
Notifications
You must be signed in to change notification settings - Fork 59
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
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1c1b02b
A simple test to reproduce #399
mvicsokolova b63ec7a
WIP: Move the logic of the gradle plugin from Kotlin repo to the libr…
mvicsokolova 2172116
The test that checks for kotlin:atomicfu dependency in the classpath …
mvicsokolova 811845a
Reverted unrelated changes
mvicsokolova 9d9c857
Apply one compiler plugin of KGP version
mvicsokolova 70c3c8d
Added a message about incompatibility of the current plugin version w…
mvicsokolova ac3c2fd
Fixes for the TC builds:
mvicsokolova 4f43a34
Minor fixup: added import of KotlinCompiler
mvicsokolova 7f10665
Delete expanded.lock file in plugin-order-bug as well
mvicsokolova d5f876c
Fixed the error messages, added a Note in the README.
mvicsokolova 240379e
Added a prerelease flag to the version-catalog project, as the check …
mvicsokolova 3b44d9e
Update atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin…
mvicsokolova 8724258
Bump the major version to 0.24.0
mvicsokolova 10527f3
Add a note, that Kotlin version may be overriden in the README.
mvicsokolova cf94043
File formatting
mvicsokolova c23783b
Move the error to checkKotlinCompatibility
mvicsokolova 6ab2911
Removed the line from Gradle configuration
mvicsokolova 5c5bce2
Fixed the section with configuration properties
mvicsokolova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...in/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicfuKotlinCompilerPluginInternal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kotlinx.atomicfu.plugin.gradle | ||
fzhinkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import org.gradle.api.provider.Provider | ||
import org.jetbrains.kotlin.gradle.plugin.* | ||
|
||
/** | ||
* This Gradle plugin applies compiler transformations to the project, it was copied from the kotlin repo (org.jetbrains.kotlinx.atomicfu.gradle.AtomicfuKotlinGradleSubplugin). | ||
* | ||
* As the sources of the compiler plugin are published as `org.jetbrains.kotlin.kotlin-atomicfu-compiler-plugin-embeddable` starting from Kotlin 1.9.0, | ||
* the Gradle plugin can access this artifact from the library and apply the transformations. | ||
* | ||
* NOTE: The version of KGP may differ from the version of Kotlin compiler, and kotlin.native.version may override the version of Kotlin native compiler. | ||
fzhinkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* So, the right behavior for the Gradle plugin would be to obtain compiler versions and apply compiler transformations separately to JVM/JS and Native targets. | ||
* This was postponed as a separate task (#408). | ||
*/ | ||
internal class AtomicfuKotlinCompilerPluginInternal : KotlinCompilerPluginSupportPlugin { | ||
|
||
companion object { | ||
const val ATOMICFU_ARTIFACT_NAME = "kotlin-atomicfu-compiler-plugin-embeddable" | ||
} | ||
|
||
mvicsokolova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean { | ||
val target = kotlinCompilation.target | ||
val project = target.project | ||
return project.needsJvmIrTransformation(target) || project.needsJsIrTransformation(target) || project.needsNativeIrTransformation(target) | ||
|
||
} | ||
|
||
override fun applyToCompilation( | ||
kotlinCompilation: KotlinCompilation<*> | ||
): Provider<List<SubpluginOption>> = | ||
kotlinCompilation.target.project.provider { emptyList() } | ||
|
||
override fun getCompilerPluginId() = "org.jetbrains.kotlinx.atomicfu" | ||
|
||
// Gets "org.jetbrains.kotlin:kotlin-atomicfu-compiler-plugin-embeddable:{KGP version}" | ||
override fun getPluginArtifact(): SubpluginArtifact { | ||
return JetBrainsSubpluginArtifact(ATOMICFU_ARTIFACT_NAME) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
integration-testing/examples/mpp-version-catalog/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile | ||
|
||
plugins { | ||
// this is necessary to avoid the plugins to be loaded multiple times | ||
// in each subproject's classloader | ||
alias(libs.plugins.kotlinMultiplatform) apply false | ||
} | ||
|
||
tasks.withType<KotlinCompile<*>>().configureEach { | ||
kotlinOptions { | ||
freeCompilerArgs += listOf("-Xskip-prerelease-check") | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration-testing/examples/mpp-version-catalog/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=2g |
21 changes: 21 additions & 0 deletions
21
integration-testing/examples/mpp-version-catalog/gradle/libs.versions.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[versions] | ||
junit = "4.13.2" | ||
kotlin = "1.9.21" | ||
atomicfu = "0.23.2-SNAPSHOT" | ||
ktor = "2.3.8" | ||
logback = "1.5.0" | ||
|
||
[libraries] | ||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } | ||
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } | ||
junit = { group = "junit", name = "junit", version.ref = "junit" } | ||
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } | ||
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } | ||
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } | ||
ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" } | ||
atomicfuGradlePlugin = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } | ||
|
||
[plugins] | ||
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } | ||
ktor = { id = "io.ktor.plugin", version.ref = "ktor" } | ||
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } |
22 changes: 22 additions & 0 deletions
22
integration-testing/examples/mpp-version-catalog/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
rootProject.name = "mpp-version-catalog" | ||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") | ||
|
||
pluginManagement { | ||
repositories { | ||
|
||
google() | ||
gradlePluginPortal() | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} | ||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} | ||
|
||
include(":shared") |
38 changes: 38 additions & 0 deletions
38
integration-testing/examples/mpp-version-catalog/shared/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
buildscript { | ||
dependencies { | ||
classpath(libs.atomicfuGradlePlugin) | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
} | ||
|
||
apply (plugin = "kotlinx-atomicfu") | ||
|
||
kotlin { | ||
|
||
jvm() | ||
|
||
js(IR) | ||
|
||
macosArm64() | ||
macosX64() | ||
linuxArm64() | ||
linuxX64() | ||
mingwX64() | ||
|
||
sourceSets { | ||
commonMain{ | ||
dependencies { | ||
implementation(kotlin("stdlib")) | ||
implementation(kotlin("test-junit")) | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
integration-testing/examples/mpp-version-catalog/shared/src/commonMain/kotlin/Greeting.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import kotlinx.atomicfu.* | ||
import kotlinx.atomicfu.locks.* | ||
import kotlin.test.* | ||
|
||
public class AtomicSampleClass { | ||
private val _x = atomic(0) | ||
val x get() = _x.value | ||
|
||
public fun doWork(finalValue: Int) { | ||
assertEquals(0, x) | ||
assertEquals(0, _x.getAndSet(3)) | ||
assertEquals(3, x) | ||
assertTrue(_x.compareAndSet(3, finalValue)) | ||
} | ||
|
||
private val lock = reentrantLock() | ||
|
||
public fun synchronizedFoo(value: Int): Int { | ||
return lock.withLock { value } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
.../functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/MppVersionCatalogTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package kotlinx.atomicfu.gradle.plugin.test.cases | ||
|
||
import kotlinx.atomicfu.gradle.plugin.test.framework.checker.* | ||
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.* | ||
import kotlin.test.* | ||
|
||
/** | ||
* This test checks the build of mpp-version-catalog project that uses a versions catalog and was a reproducer for this error (#399). | ||
*/ | ||
class MppVersionCatalogTest { | ||
private val mppWithVersionCatalog: GradleBuild = createGradleBuildFromSources("mpp-version-catalog") | ||
|
||
@Test | ||
fun testBuildWithKotlinNewerThan_1_9_0() { | ||
mppWithVersionCatalog.enableJvmIrTransformation = true | ||
mppWithVersionCatalog.enableNativeIrTransformation = true | ||
val buildResult = mppWithVersionCatalog.cleanAndBuild() | ||
assertTrue(buildResult.isSuccessful, buildResult.output) | ||
mppWithVersionCatalog.buildAndCheckBytecode() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 addorg.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 in0.23.0
and Kotlin1.9.10
)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 to1.6.0
, though I believe these are very marginal use cases.@fzhinkin WDYT? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we print the exact version here?
I think it should be enough to:
There was a problem hiding this comment.
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.