From ab259a5fb60805d44da560707d1f2f6768ed78cf Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 21 Feb 2021 16:06:25 +0300 Subject: [PATCH] Version 0.8.0 --- CHANGELOG.md | 1 + build.gradle.kts | 2 +- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 34 +-- .../mipt/npm/gradle/KSciencePublishPlugin.kt | 208 ++++++++++++++++++ .../npm/gradle/KSciencePublishingPlugin.kt | 208 ------------------ 5 files changed, 231 insertions(+), 222 deletions(-) create mode 100644 src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt delete mode 100644 src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index b6ee23b..d96c646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Ktor version to versions - Add sonatype publishing +- Per-platform release publishing ### Changed - Kotlin to 1.4.30 stable. diff --git a/build.gradle.kts b/build.gradle.kts index cede88e..74501c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,7 @@ project.extensions.findByType()?.apply{ create("publishing") { id = "ru.mipt.npm.gradle.publish" description = "The publication plugin for bintray and github" - implementationClass = "ru.mipt.npm.gradle.KSciencePublishingPlugin" + implementationClass = "ru.mipt.npm.gradle.KSciencePublishPlugin" } create("mpp") { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index c728463..0a08997 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -56,11 +56,11 @@ open class KScienceProjectPlugin : Plugin { group = "documentation" description = "Generate a README file if stub is present" - if(readmeExtension.readmeTemplate.exists()) { + if (readmeExtension.readmeTemplate.exists()) { inputs.file(readmeExtension.readmeTemplate) } readmeExtension.additionalFiles.forEach { - if(it.exists()){ + if (it.exists()) { inputs.file(it) } } @@ -75,7 +75,7 @@ open class KScienceProjectPlugin : Plugin { } } } - tasks.withType{ + tasks.withType { dependsOn(generateReadme) } } @@ -90,11 +90,11 @@ open class KScienceProjectPlugin : Plugin { } } - if(rootReadmeExtension.readmeTemplate.exists()) { + if (rootReadmeExtension.readmeTemplate.exists()) { inputs.file(rootReadmeExtension.readmeTemplate) } rootReadmeExtension.additionalFiles.forEach { - if(it.exists()){ + if (it.exists()) { inputs.file(it) } } @@ -117,7 +117,7 @@ open class KScienceProjectPlugin : Plugin { appendln("> ${ext.description}") appendln(">\n> **Maturity**: ${ext.maturity}") val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/") - if(featureString.isNotBlank()) { + if (featureString.isNotBlank()) { appendln(">\n> **Features:**") appendln(featureString) } @@ -142,30 +142,38 @@ open class KScienceProjectPlugin : Plugin { } } - tasks.withType{ + tasks.withType { dependsOn(generateReadme) } val patchChangelog by tasks.getting - val release by tasks.creating{ - afterEvaluate { + afterEvaluate { + val release by tasks.creating { group = RELEASE_GROUP description = "Publish development or production release based on version suffix" dependsOn(generateReadme) - tasks.findByName("publishAllPublicationsToSonatypeRepository")?.let { + + val publicationPlatform = project.findProperty("ci.publication.platform") as? String + val publicationName = if(publicationPlatform == null){ + "AllPublications" + } else { + publicationPlatform.capitalize() + "Publication" + } + tasks.findByName("publish${publicationName}ToSonatypeRepository")?.let { dependsOn(it) } - tasks.findByName("publishAllPublicationsToBintrayRepository")?.let { + tasks.findByName("publish${publicationName}ToBintrayRepository")?.let { dependsOn(it) } - tasks.findByName("publishAllPublicationsToSpaceRepository")?.let { + tasks.findByName("publish${publicationName}ToSpaceRepository")?.let { dependsOn(it) } } } } - companion object{ + + companion object { const val RELEASE_GROUP = "release" } } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt new file mode 100644 index 0000000..a7412aa --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt @@ -0,0 +1,208 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.jvm.tasks.Jar +import org.gradle.kotlin.dsl.* +import org.gradle.plugins.signing.SigningExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension + + +private fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT") + +open class KSciencePublishingPlugin : Plugin { + + override fun apply(project: Project): Unit = project.afterEvaluate { + if (plugins.findPlugin("maven-publish") == null) { + plugins.apply("maven-publish") + } + + val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" + val githubProject: String? by project + val vcs = findProperty("vcs") as? String + ?: githubProject?.let { "https://github.com/$githubOrg/$it" } + + configure { + plugins.withId("org.jetbrains.kotlin.js") { + val kotlin = extensions.findByType()!! + + val sourcesJar: Jar by project.tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets["main"].kotlin) + } + + publications { + create("js", MavenPublication::class) { + from(components["kotlin"]) + artifact(sourcesJar) + } + } + } + + plugins.withId("org.jetbrains.kotlin.jvm") { + val kotlin = extensions.findByType()!! + + val sourcesJar: Jar by project.tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets["main"].kotlin) + } + + publications { + create("jvm", MavenPublication::class) { + from(components["kotlin"]) + artifact(sourcesJar) + } + } + } + + val dokkaJar: Jar by tasks.creating(Jar::class) { + group = "documentation" + archiveClassifier.set("javadoc") + from(tasks.findByName("dokkaHtml")) + } + + // Process each publication we have in this project + publications.withType().forEach { publication -> + publication.artifact(dokkaJar) + publication.pom { + name.set(project.name) + description.set(project.description ?: project.name) + vcs?.let { url.set(vcs) } + + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + developers { + developer { + id.set("MIPT-NPM") + name.set("MIPT nuclear physics methods laboratory") + organization.set("MIPT") + organizationUrl.set("http://npm.mipt.ru") + } + + } + vcs?.let { + scm { + url.set(vcs) + tag.set(project.version.toString()) + //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" + } + } + } + } + + val githubUser: String? by project + val githubToken: String? by project + + if (githubProject != null && githubUser != null && githubToken != null) { + project.logger.info("Adding github publishing to project [${project.name}]") + repositories { + maven { + name = "github" + url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/") + credentials { + username = githubUser + password = githubToken + } + } + } + } + + val spaceRepo: String? by project + val spaceUser: String? by project + val spaceToken: String? by project + + if (spaceRepo != null && spaceUser != null && spaceToken != null) { + project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") + repositories { + maven { + name = "space" + url = uri(spaceRepo!!) + credentials { + username = spaceUser + password = spaceToken + } + + } + } + } + + val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" + val bintrayUser: String? by project + val bintrayApiKey: String? by project + val bintrayPublish: String? by project + + val bintrayRepo = if (isSnapshot()) { + "dev" + } else { + findProperty("bintrayRepo") as? String + } + + val projectName = project.name + + if (bintrayPublish == "true" && bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) { + project.logger.info("Adding bintray publishing to project [$projectName]") + + repositories { + maven { + name = "bintray" + url = uri( + "https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1" + ) + credentials { + username = bintrayUser + password = bintrayApiKey + } + } + } + } + + val sonatypePublish: String? by project + val sonatypeUser: String? by project + val sonatypePassword: String? by project + + val keyId: String? by project + val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey") + val signingKeyPassphrase: String? by project + + if (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null) { + val sonatypeRepo: String = if (isSnapshot()) { + "https://oss.sonatype.org/content/repositories/snapshots" + } else { + "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } + + if (plugins.findPlugin("signing") == null) { + plugins.apply("signing") + } + + extensions.configure("signing") { + if (!signingKey.isNullOrBlank()) { + //if key is provided, use it + @Suppress("UnstableApiUsage") + useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) + } // else use file signing + sign(publications) + } + + repositories { + maven { + name = "sonatype" + url = uri(sonatypeRepo) + credentials { + username = sonatypeUser + password = sonatypePassword + } + } + } + } + } + } +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt deleted file mode 100644 index d4b5054..0000000 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ /dev/null @@ -1,208 +0,0 @@ -package ru.mipt.npm.gradle - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.* -import org.gradle.plugins.signing.SigningExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension - - -open class KSciencePublishingPlugin : Plugin { - - override fun apply(project: Project): Unit = project.plugins.withId("ru.mipt.npm.common") { - project.afterEvaluate { - if (plugins.findPlugin("maven-publish") == null) { - plugins.apply("maven-publish") - } - - val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" - val githubProject: String? by project - val vcs = findProperty("vcs") as? String - ?: githubProject?.let { "https://github.com/$githubOrg/$it" } - - project.configure { - plugins.withId("org.jetbrains.kotlin.js") { - val kotlin = extensions.findByType()!! - - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) - } - - publications { - create("js", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } - } - - plugins.withId("org.jetbrains.kotlin.jvm") { - val kotlin = extensions.findByType()!! - - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) - } - - publications { - create("jvm", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } - } - - val dokkaJar: Jar by tasks.creating(Jar::class) { - group = "documentation" - archiveClassifier.set("javadoc") - from(tasks.findByName("dokkaHtml")) - } - - // Process each publication we have in this project - publications.withType().forEach { publication -> - publication.artifact(dokkaJar) - publication.pom { - name.set(project.name) - description.set(project.description ?: project.name) - vcs?.let { url.set(vcs) } - - licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - developers { - developer { - id.set("MIPT-NPM") - name.set("MIPT nuclear physics methods laboratory") - organization.set("MIPT") - organizationUrl.set("http://npm.mipt.ru") - } - - } - vcs?.let { - scm { - url.set(vcs) - tag.set(project.version.toString()) - //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" - } - } - } - } - - val githubUser: String? by project - val githubToken: String? by project - - if (githubProject != null && githubUser != null && githubToken != null) { - project.logger.info("Adding github publishing to project [${project.name}]") - repositories { - maven { - name = "github" - url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/") - credentials { - username = githubUser - password = githubToken - } - } - } - } - - val spaceRepo: String? by project - val spaceUser: String? by project - val spaceToken: String? by project - - if (spaceRepo != null && spaceUser != null && spaceToken != null) { - project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") - repositories { - maven { - name = "space" - url = uri(spaceRepo!!) - credentials { - username = spaceUser - password = spaceToken - } - - } - } - } - - val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" - val bintrayUser: String? by project - val bintrayApiKey: String? by project - val bintrayPublish: Boolean? by project - - val bintrayRepo = if (project.version.toString().contains("dev")) { - "dev" - } else { - findProperty("bintrayRepo") as? String - } - - val projectName = project.name - - if (bintrayPublish == true && bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) { - project.logger.info("Adding bintray publishing to project [$projectName]") - - repositories { - maven { - name = "bintray" - url = uri( - "https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1" - ) - credentials { - username = bintrayUser - password = bintrayApiKey - } - } - } - } - - val sonatypePublish: Boolean? by project - val sonatypeUser: String? by project - val sonatypePassword: String? by project - - val keyId: String? by project - val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey") - val signingKeyPassphrase: String? by project - - if (sonatypePublish == true && sonatypeUser != null && sonatypePassword != null) { - val sonatypeRepo: String = if (project.version.toString().contains("dev")) { - "https://oss.sonatype.org/content/repositories/snapshots" - } else { - "https://oss.sonatype.org/service/local/staging/deploy/maven2" - } - - if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") - } - - extensions.configure("signing") { - if (!signingKey.isNullOrBlank()) { - //if key is provided, use it - @Suppress("UnstableApiUsage") - useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) - } // else use file signing - sign(publications) - } - - repositories { - maven { - name = "sonatype" - url = uri(sonatypeRepo) - credentials { - username = sonatypeUser - password = sonatypePassword - } - } - } - } - } - } - } -} \ No newline at end of file