From 7f5f64c5e29d4023652a743ab826fe04cd4b0e82 Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Fri, 21 Jun 2024 15:35:06 +0200 Subject: [PATCH 1/5] Publish the Gradle plugin --- atomicfu-gradle-plugin/build.gradle.kts | 26 +++++++++++++++++++ gradle/libs.versions.toml | 1 + .../jdk-compatibility/build.gradle.kts | 17 +----------- .../examples/jvm-sample/build.gradle.kts | 13 +--------- .../examples/mpp-sample/build.gradle.kts | 15 +---------- .../shared/build.gradle.kts | 9 +------ .../producer/build.gradle.kts | 15 +---------- 7 files changed, 32 insertions(+), 64 deletions(-) diff --git a/atomicfu-gradle-plugin/build.gradle.kts b/atomicfu-gradle-plugin/build.gradle.kts index f493c9e1..dc9e167a 100644 --- a/atomicfu-gradle-plugin/build.gradle.kts +++ b/atomicfu-gradle-plugin/build.gradle.kts @@ -40,3 +40,29 @@ tasks.processResources { expand("atomicfuVersion" to project.version) } } + +signing { + // disable signing if private key isn't passed + isRequired = findProperty("libs.sign.key.private") != null +} + +gradlePlugin { + website.set("https://github.com/Kotlin/kotlinx-atomicfu") + vcsUrl.set("https://github.com/Kotlin/kotlinx-atomicfu.git") + + plugins { + create("Atomicfu") { + id = "kotlinx-atomicfu" + implementationClass = "kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin" + displayName = "Gradle plugin for kotlinx-atomicfu library" + description = "Enables efficient use of atomic operations in Kotlin multiplatform projects." + } + } +} + +// NOTE: `kotlinx-atomicfu.properties` file appears in the artifact twice, when publishing kotlin-atomicfu plugin using gradlePlugin{} block above +tasks.withType().named("processResources") { + filesMatching("META-INF/gradle-plugins/kotlinx-atomicfu.properties") { + exclude() + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7cb84375..3c488ad8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -50,4 +50,5 @@ maven = ["maven-core", "maven-pluginApi", "maven-pluginAnnotations"] gradle-nodePlugin = { id = "com.github.node-gradle.node", version.ref = "node-gradle" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binaryCompatibilityValidator"} +gradle-pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" } diff --git a/integration-testing/examples/jdk-compatibility/build.gradle.kts b/integration-testing/examples/jdk-compatibility/build.gradle.kts index 768815a5..611a8a8a 100644 --- a/integration-testing/examples/jdk-compatibility/build.gradle.kts +++ b/integration-testing/examples/jdk-compatibility/build.gradle.kts @@ -1,29 +1,14 @@ import org.jetbrains.kotlin.config.JvmTarget -buildscript { - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - 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") - } -} - group = "kotlinx.atomicfu.examples" version = "DUMMY_VERSION" plugins { kotlin("jvm") version libs.versions.kotlinVersion.get() + id("kotlinx-atomicfu") version libs.versions.atomicfuVersion.get() `maven-publish` } -apply(plugin = "kotlinx-atomicfu") - repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") diff --git a/integration-testing/examples/jvm-sample/build.gradle.kts b/integration-testing/examples/jvm-sample/build.gradle.kts index 26cf262e..d514dc73 100644 --- a/integration-testing/examples/jvm-sample/build.gradle.kts +++ b/integration-testing/examples/jvm-sample/build.gradle.kts @@ -1,21 +1,10 @@ -buildscript { - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - val atomicfuVersion = libs.versions.atomicfuVersion.get() - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion") - } -} - group = "kotlinx.atomicfu.examples" version = "DUMMY_VERSION" plugins { application kotlin("jvm") version libs.versions.kotlinVersion.get() + id("kotlinx-atomicfu") version libs.versions.atomicfuVersion.get() `maven-publish` } diff --git a/integration-testing/examples/mpp-sample/build.gradle.kts b/integration-testing/examples/mpp-sample/build.gradle.kts index d8cf3a1b..ab1b2353 100644 --- a/integration-testing/examples/mpp-sample/build.gradle.kts +++ b/integration-testing/examples/mpp-sample/build.gradle.kts @@ -4,28 +4,15 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile -buildscript { - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - val atomicfuVersion = libs.versions.atomicfuVersion.get() - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion") - } -} - group = "kotlinx.atomicfu.examples" version = "DUMMY_VERSION" plugins { kotlin("multiplatform") version libs.versions.kotlinVersion.get() `maven-publish` + id("kotlinx-atomicfu") version libs.versions.atomicfuVersion.get() } -apply(plugin = "kotlinx-atomicfu") - repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") diff --git a/integration-testing/examples/mpp-version-catalog/shared/build.gradle.kts b/integration-testing/examples/mpp-version-catalog/shared/build.gradle.kts index c5c8040e..7a575575 100644 --- a/integration-testing/examples/mpp-version-catalog/shared/build.gradle.kts +++ b/integration-testing/examples/mpp-version-catalog/shared/build.gradle.kts @@ -4,12 +4,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile -buildscript { - dependencies { - classpath(libs.atomicfuGradlePlugin) - } -} - repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") @@ -18,10 +12,9 @@ repositories { plugins { alias(libs.plugins.kotlinMultiplatform) + id("kotlinx-atomicfu") version libs.versions.atomicfu.get() } -apply (plugin = "kotlinx-atomicfu") - kotlin { jvm() diff --git a/integration-testing/examples/multi-module-test/producer/build.gradle.kts b/integration-testing/examples/multi-module-test/producer/build.gradle.kts index 4e0e044d..abba904d 100644 --- a/integration-testing/examples/multi-module-test/producer/build.gradle.kts +++ b/integration-testing/examples/multi-module-test/producer/build.gradle.kts @@ -1,21 +1,8 @@ -buildscript { - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - val atomicfuVersion = libs.versions.atomicfuVersion.get() - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion") - } -} - plugins { kotlin("multiplatform") version libs.versions.kotlinVersion.get() + id("kotlinx-atomicfu") version libs.versions.atomicfuVersion.get() } -apply(plugin = "kotlinx-atomicfu") - repositories { mavenLocal() mavenCentral() From ef7485aeb8ccba6c1bc6922478a071680c2f9dac Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Mon, 24 Jun 2024 12:47:37 +0200 Subject: [PATCH 2/5] Remove gradle-pluginPublish version from the catalog --- gradle/libs.versions.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3c488ad8..7cb84375 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -50,5 +50,4 @@ maven = ["maven-core", "maven-pluginApi", "maven-pluginAnnotations"] gradle-nodePlugin = { id = "com.github.node-gradle.node", version.ref = "node-gradle" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binaryCompatibilityValidator"} -gradle-pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" } From d3a2817569fbd82507fef240c796605371663a39 Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Mon, 24 Jun 2024 13:20:36 +0200 Subject: [PATCH 3/5] Removed META-INF/kotlinx-atomicfu.properties file, as it's already generated by gradlePlugin{} block --- atomicfu-gradle-plugin/build.gradle.kts | 7 ------- .../META-INF/gradle-plugins/kotlinx-atomicfu.properties | 1 - 2 files changed, 8 deletions(-) delete mode 100644 atomicfu-gradle-plugin/src/main/resources/META-INF/gradle-plugins/kotlinx-atomicfu.properties diff --git a/atomicfu-gradle-plugin/build.gradle.kts b/atomicfu-gradle-plugin/build.gradle.kts index dc9e167a..4d343b1f 100644 --- a/atomicfu-gradle-plugin/build.gradle.kts +++ b/atomicfu-gradle-plugin/build.gradle.kts @@ -59,10 +59,3 @@ gradlePlugin { } } } - -// NOTE: `kotlinx-atomicfu.properties` file appears in the artifact twice, when publishing kotlin-atomicfu plugin using gradlePlugin{} block above -tasks.withType().named("processResources") { - filesMatching("META-INF/gradle-plugins/kotlinx-atomicfu.properties") { - exclude() - } -} diff --git a/atomicfu-gradle-plugin/src/main/resources/META-INF/gradle-plugins/kotlinx-atomicfu.properties b/atomicfu-gradle-plugin/src/main/resources/META-INF/gradle-plugins/kotlinx-atomicfu.properties deleted file mode 100644 index ff169aee..00000000 --- a/atomicfu-gradle-plugin/src/main/resources/META-INF/gradle-plugins/kotlinx-atomicfu.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin \ No newline at end of file From 74805152b4ce81b92af0ae78011cd0cf21aeaaab Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Thu, 27 Jun 2024 15:25:17 +0200 Subject: [PATCH 4/5] WIP: pack the artifacts, only if publich plugin is not applied yet --- atomicfu-gradle-plugin/build.gradle.kts | 1 + .../main/kotlin/kotlin-jvm-conventions.gradle.kts | 12 +++++++----- gradle/libs.versions.toml | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/atomicfu-gradle-plugin/build.gradle.kts b/atomicfu-gradle-plugin/build.gradle.kts index 4d343b1f..19426021 100644 --- a/atomicfu-gradle-plugin/build.gradle.kts +++ b/atomicfu-gradle-plugin/build.gradle.kts @@ -3,6 +3,7 @@ */ plugins { + alias(libs.plugins.gradle.pluginPublish) id("kotlin-jvm-conventions") id("java-gradle-plugin") } diff --git a/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts index 88ffe5b1..d6588d43 100644 --- a/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts @@ -14,11 +14,13 @@ val sourcesJar by tasks.registering(Jar::class) { } publishing { - // Configure java publications for non-MPP projects - publications { - create("maven") { - from(components["java"]) - artifact(sourcesJar) + if (!pluginManager.hasPlugin("com.gradle.plugin-publish")) { + // Configure java publications for non-MPP projects + publications { + create("maven") { + from(components["java"]) + artifact(sourcesJar) + } } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7cb84375..1d4af3d1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,6 +8,7 @@ maven = "3.5.3" maven-pluginTools = "3.5" node-gradle = "3.1.1" rhino = "1.7.10" +gradle-plugin-publish = "1.2.1" [libraries] @@ -50,4 +51,5 @@ maven = ["maven-core", "maven-pluginApi", "maven-pluginAnnotations"] gradle-nodePlugin = { id = "com.github.node-gradle.node", version.ref = "node-gradle" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binaryCompatibilityValidator"} +gradle-pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" } From 1e3d4c9ce62704357bde9cc27a85b4d6234cb6b5 Mon Sep 17 00:00:00 2001 From: Dmitrii Krasnov Date: Thu, 27 Jun 2024 17:54:01 +0200 Subject: [PATCH 5/5] Reorganised convention plugins --- .gitignore | 3 ++- atomicfu-maven-plugin/build.gradle.kts | 2 +- atomicfu-transformer/build.gradle.kts | 2 +- ...ts => base-publish-conventions.gradle.kts} | 15 -------------- .../kotlin/kotlin-jvm-conventions.gradle.kts | 20 +------------------ .../kotlin-jvm-publish-conventions.gradle.kts | 20 +++++++++++++++++++ ...ltiplatform-publish-conventions.gradle.kts | 2 +- ...ublish-with-javadoc-conventions.gradle.kts | 17 ++++++++++++++++ integration-testing/build.gradle.kts | 2 +- 9 files changed, 44 insertions(+), 39 deletions(-) rename buildSrc/src/main/kotlin/{publish-conventions.gradle.kts => base-publish-conventions.gradle.kts} (76%) create mode 100644 buildSrc/src/main/kotlin/kotlin-jvm-publish-conventions.gradle.kts create mode 100644 buildSrc/src/main/kotlin/publish-with-javadoc-conventions.gradle.kts diff --git a/.gitignore b/.gitignore index c4b47e74..5beb4c23 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.iml */target/* build -.gradle \ No newline at end of file +.gradle +.kotlin \ No newline at end of file diff --git a/atomicfu-maven-plugin/build.gradle.kts b/atomicfu-maven-plugin/build.gradle.kts index 3a9b99aa..76713914 100644 --- a/atomicfu-maven-plugin/build.gradle.kts +++ b/atomicfu-maven-plugin/build.gradle.kts @@ -4,7 +4,7 @@ plugins { `maven-publish` - id("kotlin-jvm-conventions") + id("kotlin-jvm-publish-conventions") } dependencies { diff --git a/atomicfu-transformer/build.gradle.kts b/atomicfu-transformer/build.gradle.kts index 580578fa..38aa5980 100644 --- a/atomicfu-transformer/build.gradle.kts +++ b/atomicfu-transformer/build.gradle.kts @@ -3,7 +3,7 @@ */ plugins { - id("kotlin-jvm-conventions") + id("kotlin-jvm-publish-conventions") } dependencies { diff --git a/buildSrc/src/main/kotlin/publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/base-publish-conventions.gradle.kts similarity index 76% rename from buildSrc/src/main/kotlin/publish-conventions.gradle.kts rename to buildSrc/src/main/kotlin/base-publish-conventions.gradle.kts index 2ae3c4e9..f45639d5 100644 --- a/buildSrc/src/main/kotlin/publish-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/base-publish-conventions.gradle.kts @@ -3,12 +3,6 @@ plugins { signing } -val javadocJar by tasks.register("javadocJar") { - description = "Create a Javadoc JAR. Empty by default." - // Create an empty Javadoc JAR to satisfy Maven Central requirements. - archiveClassifier.set("javadoc") -} - publishing { repositories { maven { @@ -52,15 +46,6 @@ publishing { signPublicationIfKeyPresent(project, this) - // TODO(Dmitrii Krasnov): https://github.com/Kotlin/kotlinx-atomicfu/issues/421 - // Figure out if there's an alternative to string-based config - // (if the name changes this config will silently stop working). - // Maybe the Javadoc JAR can always be added? - // add empty javadocs - - if (name != "kotlinMultiplatform") { // The root module gets the JVM's javadoc JAR - artifact(javadocJar) - } } tasks.withType().configureEach { diff --git a/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts index d6588d43..32d816a0 100644 --- a/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts @@ -2,29 +2,11 @@ plugins { // Regular java modules need 'java-library' plugin for proper publication `java-library` kotlin("jvm") - id("publish-conventions") + id("base-publish-conventions") id("common-conventions") id("kotlin-base-conventions") } -// MPP projects pack their sources automatically, java libraries need to explicitly pack them -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from("src/main/kotlin") -} - -publishing { - if (!pluginManager.hasPlugin("com.gradle.plugin-publish")) { - // Configure java publications for non-MPP projects - publications { - create("maven") { - from(components["java"]) - artifact(sourcesJar) - } - } - } -} - kotlin { jvmToolchain(8) } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kotlin-jvm-publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-jvm-publish-conventions.gradle.kts new file mode 100644 index 00000000..683f6a91 --- /dev/null +++ b/buildSrc/src/main/kotlin/kotlin-jvm-publish-conventions.gradle.kts @@ -0,0 +1,20 @@ +plugins { + id("kotlin-jvm-conventions") + id("publish-with-javadoc-conventions") +} + +// MPP projects pack their sources automatically, java libraries need to explicitly pack them +val sourcesJar by tasks.registering(Jar::class) { + archiveClassifier.set("sources") + from("src/main/kotlin") +} + +publishing { + // Configure java publications for non-MPP projects + publications { + create("maven") { + from(components["java"]) + artifact(sourcesJar) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kotlin-multiplatform-publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-multiplatform-publish-conventions.gradle.kts index 1f3d6bc0..5e45483a 100644 --- a/buildSrc/src/main/kotlin/kotlin-multiplatform-publish-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-multiplatform-publish-conventions.gradle.kts @@ -2,7 +2,7 @@ import groovy.util.Node import groovy.util.NodeList plugins { - id("publish-conventions") + id("publish-with-javadoc-conventions") } afterEvaluate { diff --git a/buildSrc/src/main/kotlin/publish-with-javadoc-conventions.gradle.kts b/buildSrc/src/main/kotlin/publish-with-javadoc-conventions.gradle.kts new file mode 100644 index 00000000..617b2f75 --- /dev/null +++ b/buildSrc/src/main/kotlin/publish-with-javadoc-conventions.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("base-publish-conventions") +} + +val javadocJar by tasks.register("javadocJar") { + description = "Create a Javadoc JAR. Empty by default." + // Create an empty Javadoc JAR to satisfy Maven Central requirements. + archiveClassifier.set("javadoc") +} + +publishing { + publications.withType().configureEach { + if (name != "kotlinMultiplatform") { // The root module gets the JVM's javadoc JAR + artifact(javadocJar) + } + } +} \ No newline at end of file diff --git a/integration-testing/build.gradle.kts b/integration-testing/build.gradle.kts index 812f19ff..3a9c97b2 100644 --- a/integration-testing/build.gradle.kts +++ b/integration-testing/build.gradle.kts @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader plugins { - id("kotlin-jvm-conventions") + id("kotlin-jvm-publish-conventions") } java {