From fdf88327b49e5a09408890307c83d117019665f2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 16 Feb 2021 18:19:22 +0300 Subject: [PATCH 1/2] Sonatype publication --- CHANGELOG.md | 1 + build.gradle.kts | 27 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ru/mipt/npm/gradle/KScienceExtension.kt | 4 +- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 25 ++- .../mipt/npm/gradle/KSciencePublishPlugin.kt | 190 +++++++++++++++++- .../ru/mipt/npm/gradle/internal/publish.kt | 159 --------------- 7 files changed, 224 insertions(+), 184 deletions(-) delete mode 100644 src/main/kotlin/ru/mipt/npm/gradle/internal/publish.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f2715..cb72b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Ktor version to versions +- Add sonatype publishing ### Changed - Kotlin to 1.4.30 stable diff --git a/build.gradle.kts b/build.gradle.kts index 7573a8c..204701e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,11 +2,14 @@ plugins { `java-gradle-plugin` `kotlin-dsl` `maven-publish` + id("de.marcphilipp.nexus-publish") version "0.4.0" id("org.jetbrains.changelog") version "1.0.0" } group = "ru.mipt.npm" -version = "0.7.6" +version = "0.7.7" + +description = "Build tools for DataForge and kscience projects" repositories { gradlePluginPortal() @@ -119,24 +122,18 @@ publishing { } } - val bintrayUser: String? by project - val bintrayApiKey: String? by project - val projectName = project.name + val sonatypeUser: String? by project + val sonatypePassword: String? by project - if (bintrayUser != null && bintrayApiKey != null) { - repositories { - maven { - name = "bintray" - url = uri( - "https://api.bintray.com/maven/mipt-npm/dev/$projectName/;publish=1;override=1" - ) - credentials { - username = bintrayUser - password = bintrayApiKey + if (sonatypeUser != null && sonatypePassword != null) { + nexusPublishing { + repositories { + sonatype{ + username.set(sonatypeUser) + password.set(sonatypePassword) } } } - } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28ff446..2a56324 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index e7e3d59..27f0497 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -2,12 +2,12 @@ package ru.mipt.npm.gradle import org.gradle.api.Project import org.gradle.api.plugins.ApplicationPlugin +import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.findByType import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import ru.mipt.npm.gradle.internal.configurePublishing import ru.mipt.npm.gradle.internal.defaultPlatform import ru.mipt.npm.gradle.internal.useCommonDependency import ru.mipt.npm.gradle.internal.useFx @@ -128,7 +128,7 @@ class KScienceExtension(val project: Project) { } fun publish() { - project.configurePublishing() + project.plugins.apply(KSciencePublishPlugin::class) } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index c5ccd8f..dd725d5 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -13,15 +13,25 @@ import kotlin.collections.component2 class KSciencePublishingExtension(val project: Project) { var vcs: String? by project.extra + + // github publishing var githubOrg: String? by project.extra var githubProject: String? by project.extra + + // Space publishing var spaceRepo: String? by project.extra var spaceUser: String? by project.extra var spaceToken: String? by project.extra + + // Bintray publishing var bintrayOrg: String? by project.extra var bintrayUser: String? by project.extra var bintrayApiKey: String? by project.extra var bintrayRepo: String? by project.extra + + // Sonatype publising + var sonatypeUser: String? by project.extra + var sonatypePassword: String? by project.extra } @@ -139,11 +149,16 @@ open class KScienceProjectPlugin : Plugin { val patchChangelog by tasks.getting val release by tasks.creating{ - group = RELEASE_GROUP - description = "Publish development or production release based on version suffix" - dependsOn(generateReadme, patchChangelog) - tasks.findByName("publishAllPublicationsToBintrayRepository")?.let { - dependsOn(it) + afterEvaluate { + group = RELEASE_GROUP + description = "Publish development or production release based on version suffix" + dependsOn(generateReadme) + tasks.findByName("publishAllPublicationsToBintrayRepository")?.let { + dependsOn(it) + } + tasks.findByName("publishAllPublicationsToSpaceRepository")?.let { + dependsOn(it) + } } } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt index c45e556..3558c99 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt @@ -2,12 +2,198 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import ru.mipt.npm.gradle.internal.configurePublishing +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 KSciencePublishPlugin : Plugin { override fun apply(project: Project): Unit = project.plugins.withId("ru.mipt.npm.kscience") { - project.configurePublishing() + project.run { + 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" } + +// if (vcs == null) { +// project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") +// return +// } + + 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) + } + } + } + + + // Process each publication we have in this project + publications.withType().forEach { publication -> + publication.pom { + name.set(project.name) + description.set(project.description) + 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 bintrayRepo = if (project.version.toString().contains("dev")) { + "dev" + } else { + findProperty("bintrayRepo") as? String + } + + val projectName = project.name + + if (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 sonatypeUser: String? by project + val sonatypePassword: String? by project + + if (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.findByType()?.apply { + useGpgCmd() + sign(publications) + } + + repositories { + maven { + name = "sonatype" + url = uri(sonatypeRepo) + credentials { + username = sonatypeUser + password = sonatypePassword + } + } + } + } + + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/publish.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/publish.kt deleted file mode 100644 index 58f8b02..0000000 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publish.kt +++ /dev/null @@ -1,159 +0,0 @@ -package ru.mipt.npm.gradle.internal - -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.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension - -internal fun Project.configurePublishing() { - 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" } - -// if (vcs == null) { -// project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") -// return -// } - - 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) - } - } - } - - - // Process each publication we have in this project - publications.withType().forEach { publication -> - publication.pom { - name.set(project.name) - description.set(project.description) - 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()) - } - } - } - } - - 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 bintrayRepo = if (project.version.toString().contains("dev")) { - "dev" - } else { - findProperty("bintrayRepo") as? String - } - - val projectName = project.name - - if (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 - } - } - } - - } - } -} \ No newline at end of file From e0b9fe2306ad16b9cdbc2385315ecce8dd086bdd Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 16 Feb 2021 18:31:43 +0300 Subject: [PATCH 2/2] Add README.md --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0bffb2b --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# KScience build tools + +A collection of gradle plugins for building and publishin *kscience* and *dataforge* projects. + +## ru.mipt.npm.kscience +A primary plugin. When used with kotlin-jvm, kotlin-js or kotlin-mulitplatform configures the project for appropriate target. + +## ru.mipt.npm.project +Root project tool including JetBrains changelog plugin an kotlin binary compatibility validator tool. + +## ru.mipt.npm.publish +Enables publishing to maven-central, bintray, Space and github. + +## ru.mipt.npm.mpp +`= kotlin("multiplatform") + ru.mipt.npm.kscience` + +Includes JVM-IR and JS-IR-Browser targets. + +## ru.mipt.npm.jvm +`= kotlin("jvm") + ru.mipt.npm.kscience` + +## ru.mipt.npm.js +`= kotlin("js + ru.mipt.npm.kscience` + +## ru.mipt.npm.native +add default native targets to `ru.mipt.npm.mpp` + +## ru.mipt.npm.node +add node target to `ru.mipt.npm.mpp` \ No newline at end of file