diff --git a/atomicfu-gradle-plugin/build.gradle b/atomicfu-gradle-plugin/build.gradle index 4c43f934..1313f499 100644 --- a/atomicfu-gradle-plugin/build.gradle +++ b/atomicfu-gradle-plugin/build.gradle @@ -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' diff --git a/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt b/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt index 3d2b933c..69e67924 100644 --- a/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt +++ b/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt @@ -45,12 +45,34 @@ open class AtomicFUGradlePlugin : Plugin { val pluginVersion = rootProject.buildscript.configurations.findByName("classpath") ?.allDependencies?.find { it.name == "atomicfu-gradle-plugin" }?.version extensions.add(EXTENSION_NAME, AtomicFUPluginExtension(pluginVersion)) + checkClasspathForAtomicfuCompilerPlugin() applyAtomicfuCompilerPlugin() configureDependencies() configureTasks() } } +private fun Project.checkClasspathForAtomicfuCompilerPlugin() { + 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,\n" + + "as well as a dependency to the atomicfu-gradle-plugin:\n" + + "buildscript {\n" + + " repositories {\n" + + " mavenCentral() \n" + + " }\n" + + "\n" + + " dependencies {\n" + + " val kotlinVersion = $kotlinVersion\n" + + " classpath(\"org.jetbrains.kotlinx:atomicfu-gradle-plugin:$kotlinVersion\")\n" + + " classpath(\"org.jetbrains.kotlin:atomicfu:$kotlinVersion\")\n" + + " }\n" + + "}\n\n" + + "apply(plugin = \"kotlinx-atomicfu\")" + ) +} + private fun Project.checkCompatibility() { val currentGradleVersion = GradleVersion.current() val kotlinVersion = getKotlinVersion() @@ -204,8 +226,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()}") } } } diff --git a/atomicfu-maven-plugin/build.gradle b/atomicfu-maven-plugin/build.gradle index 5756df9c..9769b9b6 100644 --- a/atomicfu-maven-plugin/build.gradle +++ b/atomicfu-maven-plugin/build.gradle @@ -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" diff --git a/atomicfu-transformer/build.gradle b/atomicfu-transformer/build.gradle index be540524..6ef1a41c 100644 --- a/atomicfu-transformer/build.gradle +++ b/atomicfu-transformer/build.gradle @@ -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" diff --git a/atomicfu/build.gradle b/atomicfu/build.gradle index d20bb341..c354f9cb 100644 --- a/atomicfu/build.gradle +++ b/atomicfu/build.gradle @@ -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 { @@ -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 { @@ -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' } } @@ -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 { @@ -103,7 +105,7 @@ kotlin { jvmMain { dependencies { - implementation 'org.jetbrains.kotlin:kotlin-stdlib' + compileOnly 'org.jetbrains.kotlin:kotlin-stdlib' } } jvmTest { diff --git a/gradle/publish-mpp-root-module-in-platform.gradle b/gradle/publish-mpp-root-module-in-platform.gradle index 94920bd6..3e0a105d 100644 --- a/gradle/publish-mpp-root-module-in-platform.gradle +++ b/gradle/publish-mpp-root-module-in-platform.gradle @@ -25,13 +25,16 @@ 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") + } } } @@ -39,4 +42,4 @@ project.ext.publishPlatformArtifactsInRootModule = { MavenPublication platformPu dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) } } -} \ No newline at end of file +} diff --git a/integration-testing/build.gradle.kts b/integration-testing/build.gradle.kts index 0a4392f3..efb26b15 100644 --- a/integration-testing/build.gradle.kts +++ b/integration-testing/build.gradle.kts @@ -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") diff --git a/integration-testing/examples/jvm-sample/build.gradle.kts b/integration-testing/examples/jvm-sample/build.gradle.kts index 29bdde6a..f1a0f872 100644 --- a/integration-testing/examples/jvm-sample/build.gradle.kts +++ b/integration-testing/examples/jvm-sample/build.gradle.kts @@ -1,10 +1,13 @@ buildscript { repositories { mavenLocal() + mavenCentral() } dependencies { - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}") + val kotlinVersion = libs.versions.atomicfuVersion.get() + classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$kotlinVersion") + classpath("org.jetbrains.kotlin:atomicfu:$kotlinVersion") } } diff --git a/integration-testing/examples/jvm-sample/gradle.properties b/integration-testing/examples/jvm-sample/gradle.properties index b75bc9ee..a5cb67ce 100644 --- a/integration-testing/examples/jvm-sample/gradle.properties +++ b/integration-testing/examples/jvm-sample/gradle.properties @@ -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 diff --git a/integration-testing/examples/mpp-sample/build.gradle.kts b/integration-testing/examples/mpp-sample/build.gradle.kts index f7bb99b8..4e7ab8a8 100644 --- a/integration-testing/examples/mpp-sample/build.gradle.kts +++ b/integration-testing/examples/mpp-sample/build.gradle.kts @@ -1,15 +1,16 @@ /* * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ - buildscript { repositories { mavenLocal() - mavenCentral() + mavenCentral() } dependencies { - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${libs.versions.atomicfuVersion.get()}") + val kotlinVersion = libs.versions.atomicfuVersion.get() + classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$kotlinVersion") + classpath("org.jetbrains.kotlin:atomicfu:$kotlinVersion") } } diff --git a/integration-testing/examples/mpp-sample/gradle.properties b/integration-testing/examples/mpp-sample/gradle.properties index b75bc9ee..a5cb67ce 100644 --- a/integration-testing/examples/mpp-sample/gradle.properties +++ b/integration-testing/examples/mpp-sample/gradle.properties @@ -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 diff --git a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/smoke/DependencyCheckerTest.kt b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/smoke/DependencyCheckerTest.kt index 929fb089..7fc0b48d 100644 --- a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/smoke/DependencyCheckerTest.kt +++ b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/smoke/DependencyCheckerTest.kt @@ -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.* @@ -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" + @@ -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" + @@ -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", diff --git a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/BuildRunner.kt b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/BuildRunner.kt index 4fada6e8..6daf7149 100644 --- a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/BuildRunner.kt +++ b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/BuildRunner.kt @@ -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") diff --git a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/Environment.kt b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/Environment.kt index 87bef24f..6e06fb7d 100644 --- a/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/Environment.kt +++ b/integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/Environment.kt @@ -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("..")