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 1 commit
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
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,35 @@ 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" }
?: 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"
)
}

private fun Project.checkCompatibility() {
val currentGradleVersion = GradleVersion.current()
val kotlinVersion = getKotlinVersion()
Expand Down Expand Up @@ -204,8 +227,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
2 changes: 1 addition & 1 deletion atomicfu-maven-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply from: rootProject.file('gradle/compile-options.gradle')
ext.configureKotlin()

dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api project(":atomicfu-transformer")
api "org.apache.maven:maven-core:$maven_version"
api "org.apache.maven:maven-plugin-api:$maven_version"
Expand Down
2 changes: 1 addition & 1 deletion atomicfu-transformer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/compile-options.gradle')
ext.configureKotlin()

dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api "org.ow2.asm:asm:$asm_version"
api "org.ow2.asm:asm-commons:$asm_version"
api "org.ow2.asm:asm-tree:$asm_version"
Expand Down
12 changes: 7 additions & 5 deletions atomicfu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ kotlin {
sourceSets {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
}
commonTest {
Expand All @@ -67,7 +68,8 @@ kotlin {
jsMain {
dependsOn(sourceSets.jsAndWasmSharedMain)
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib-js'
compileOnly 'org.jetbrains.kotlin:kotlin-dom-api-compat'
}
}
jsTest {
Expand All @@ -79,7 +81,7 @@ kotlin {
wasmJsMain {
dependsOn(sourceSets.jsAndWasmSharedMain)
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
}
}

Expand All @@ -92,7 +94,7 @@ kotlin {
wasmWasiMain {
dependsOn(sourceSets.jsAndWasmSharedMain)
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi'
}
}
wasmWasiTest {
Expand All @@ -103,7 +105,7 @@ kotlin {

jvmMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
}
}
jvmTest {
Expand Down
19 changes: 11 additions & 8 deletions gradle/publish-mpp-root-module-in-platform.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ project.ext.publishPlatformArtifactsInRootModule = { MavenPublication platformPu
root.appendNode("packaging", "pom")

// Remove the original platform dependencies and add a single dependency on the platform module:
Node dependencies = (root.get("dependencies") as NodeList).get(0) as Node
dependencies.children().toList().each { dependencies.remove(it as Node) }
Node singleDependency = dependencies.appendNode("dependency")
singleDependency.appendNode("groupId", platformPublication.groupId)
singleDependency.appendNode("artifactId", platformPublication.artifactId)
singleDependency.appendNode("version", platformPublication.version)
singleDependency.appendNode("scope", "compile")
def allDependencies = (root.get("dependencies") as NodeList)
if (!allDependencies.isEmpty()) {
Node dependencies = allDependencies.get(0) as Node
dependencies.children().toList().each { dependencies.remove(it as Node) }
Node singleDependency = dependencies.appendNode("dependency")
singleDependency.appendNode("groupId", platformPublication.groupId)
singleDependency.appendNode("artifactId", platformPublication.artifactId)
singleDependency.appendNode("version", platformPublication.version)
singleDependency.appendNode("scope", "compile")
}
}
}

tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
}
}
}
}
3 changes: 1 addition & 2 deletions integration-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ val mavenTest by tasks.registering(Test::class) {
val functionalTest by tasks.registering(Test::class) {
testClassesDirs = sourceSets["functionalTest"].output.classesDirs
classpath = sourceSets["functionalTest"].runtimeClasspath

systemProperties["kotlinVersion"] = kotlin_version

systemProperties["atomicfuVersion"] = atomicfu_snapshot_version

dependsOn(":atomicfu-gradle-plugin:publishToMavenLocal")
Expand Down
6 changes: 5 additions & 1 deletion integration-testing/examples/jvm-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
buildscript {
repositories {
mavenLocal()
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that in the future it is better to use custom repositories for functional tests, rather than mavenLocal()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mavenCentral()
}

dependencies {
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}")
val atomicfuVersion = libs.versions.atomicfuVersion.get()
val kotlinVersion = libs.versions.kotlinVersion.get()
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion")
classpath("org.jetbrains.kotlin:atomicfu:$kotlinVersion")
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration-testing/examples/jvm-sample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
##
kotlin_version=1.9.20
kotlin_version=1.9.21
atomicfu_version=0.23.1-SNAPSHOT
6 changes: 4 additions & 2 deletions integration-testing/examples/mpp-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/*
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

buildscript {
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}")
val atomicfuVersion = libs.versions.atomicfuVersion.get()
val kotlinVersion = libs.versions.kotlinVersion.get()
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion")
classpath("org.jetbrains.kotlin:atomicfu:$kotlinVersion")
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration-testing/examples/mpp-sample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
##
kotlin_version=1.9.20
kotlin_version=1.9.21
atomicfu_version=0.23.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kotlinx.atomicfu.gradle.plugin.test.cases.smoke

import kotlinx.atomicfu.gradle.plugin.test.framework.runner.BuildResult
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.atomicfuVersion
import java.io.File
import kotlin.test.*

Expand All @@ -17,7 +18,7 @@ class DependencyParserSmokeTest {
"Root project 'jvm-sample'\n" +
"------------------------------------------------------------\n" +
"compileClasspath - Compile classpath for null/main.\n" +
"+--- org.jetbrains.kotlinx:atomicfu-jvm:0.23.1-SNAPSHOT\n" +
"+--- org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion\n" +
"+--- org.jetbrains.kotlin:kotlin-stdlib:1.9.0\n" +
"| +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0\n" +
"| \\--- org.jetbrains:annotations:13.0\n" +
Expand All @@ -28,10 +29,10 @@ class DependencyParserSmokeTest {
" \\--- org.hamcrest:hamcrest-core:1.3\n" +
"\n" +
"compileOnly - Compile only dependencies for null/main. (n)\n" +
"\\--- org.jetbrains.kotlinx:atomicfu-jvm:0.23.1-SNAPSHOT (n)\n" +
"\\--- org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion (n)\n" +
"\n" +
"compileOnlyDependenciesMetadata\n" +
"\\--- org.jetbrains.kotlinx:atomicfu-jvm:0.23.1-SNAPSHOT\n" +
"\\--- org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion\n" +
"\n" +
"default - Configuration for default artifacts. (n)\n" +
"No dependencies\n" +
Expand Down Expand Up @@ -73,7 +74,7 @@ class DependencyParserSmokeTest {
)
assertEquals(
listOf(
"org.jetbrains.kotlinx:atomicfu-jvm:0.23.1-SNAPSHOT",
"org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion",
"org.jetbrains.kotlin:kotlin-stdlib:1.9.0",
"org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0",
"org.jetbrains:annotations:13.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ internal class GradleBuild(val projectName: String, val targetDir: File) {

private val properties
get() = buildList {
add("-P$KOTLIN_VERSION=$kotlinVersion")
add("-P${ATOMICFU_VERSION}=$atomicfuVersion")
add("-P$ENABLE_JVM_IR_TRANSFORMATION=$enableJvmIrTransformation")
add("-P$ENABLE_JS_IR_TRANSFORMATION=$enableJsIrTransformation")
add("-P$ENABLE_NATIVE_IR_TRANSFORMATION=$enableNativeIrTransformation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal const val ENABLE_NATIVE_IR_TRANSFORMATION = "kotlinx.atomicfu.enableNat
internal const val DUMMY_VERSION = "DUMMY_VERSION"

internal val atomicfuVersion = System.getProperty("atomicfuVersion")
internal val kotlinVersion = System.getProperty("kotlinVersion")

internal val gradleWrapperDir = File("..")

Expand Down