From 7d666cb6c7e932d8de62b47c023329cbd349a723 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Feb 2021 20:11:42 +0300 Subject: [PATCH 01/18] Add features mnemonic to root project readme --- src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt index cf8c027..5977e9a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt @@ -79,7 +79,7 @@ class KScienceReadmeExtension(val project: Project) { */ fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { features.forEach { - appendln("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") + appendLine("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") } } From a7f4c541f4c2f65815f2f1a79ba15a7f4e306a6c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Feb 2021 20:34:13 +0300 Subject: [PATCH 02/18] Fix readme properties in root project readme --- CHANGELOG.md | 1 + build.gradle.kts | 2 +- src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74574b1..733b890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security + ## [0.8.0] ### Added - Ktor version to versions diff --git a/build.gradle.kts b/build.gradle.kts index cede88e..4b5b363 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.0" +version = "0.8.1" description = "Build tools for DataForge and kscience projects" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt index 5977e9a..cf8c027 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt @@ -79,7 +79,7 @@ class KScienceReadmeExtension(val project: Project) { */ fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { features.forEach { - appendLine("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") + appendln("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") } } From 4c656a3f61327dff322f52a17aeb240decfa4622 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Feb 2021 20:35:12 +0300 Subject: [PATCH 03/18] Move maven-publish to configuration phase --- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 11 +- .../npm/gradle/KSciencePublishingPlugin.kt | 312 +++++++++--------- 2 files changed, 163 insertions(+), 160 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 0a08997..9e26f2d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -11,6 +11,7 @@ import org.jetbrains.dokka.gradle.DokkaTask import kotlin.collections.component1 import kotlin.collections.component2 +@Suppress("unused") class KSciencePublishingExtension(val project: Project) { var vcs: String? by project.extra @@ -126,12 +127,8 @@ open class KScienceProjectPlugin : Plugin { appendln("
") } - val rootReadmeProperties: Map = mapOf( - "name" to project.name, - "group" to project.group, - "version" to project.version, - "modules" to modulesString - ) + val rootReadmeProperties: Map = + rootReadmeExtension.properties + ("modules" to modulesString) readmeFile.writeText( SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate) @@ -155,7 +152,7 @@ open class KScienceProjectPlugin : Plugin { dependsOn(generateReadme) val publicationPlatform = project.findProperty("ci.publication.platform") as? String - val publicationName = if(publicationPlatform == null){ + val publicationName = if (publicationPlatform == null) { "AllPublications" } else { publicationPlatform.capitalize() + "Publication" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index a7412aa..d02563d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -15,190 +15,196 @@ private fun Project.isSnapshot() = version.toString().contains("dev") || version open class KSciencePublishingPlugin : Plugin { - override fun apply(project: Project): Unit = project.afterEvaluate { - if (plugins.findPlugin("maven-publish") == null) { - plugins.apply("maven-publish") + override fun apply(project: Project): Unit { + project.run { + if (plugins.findPlugin("maven-publish") == null) { + plugins.apply("maven-publish") + } + 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 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.afterEvaluate { - configure { - plugins.withId("org.jetbrains.kotlin.js") { - val kotlin = extensions.findByType()!! + 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" } - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) + configure { + val dokkaJar: Jar by tasks.creating(Jar::class) { + group = "documentation" + archiveClassifier.set("javadoc") + from(tasks.findByName("dokkaHtml")) } - publications { - create("js", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } - } + // 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) } - 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") + 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=]/*Повторить предыдущую ссылку*/" + } + 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 + 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 + 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 + 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 - } + 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 bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" + val bintrayUser: String? by project + val bintrayApiKey: String? by project + val bintrayPublish: 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" + val bintrayRepo = if (isSnapshot()) { + "dev" } else { - "https://oss.sonatype.org/service/local/staging/deploy/maven2" + findProperty("bintrayRepo") as? String } - if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") + 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 + } + } + } } - extensions.configure("signing") { - if (!signingKey.isNullOrBlank()) { - //if key is provided, use it - @Suppress("UnstableApiUsage") - useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) - } // else use file signing - sign(publications) - } + val sonatypePublish: String? by project + val sonatypeUser: String? by project + val sonatypePassword: String? by project - repositories { - maven { - name = "sonatype" - url = uri(sonatypeRepo) - credentials { - username = sonatypeUser - password = sonatypePassword + 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 + } } } } From a6c7287bb10f9440c04f5ce8f92c1a4a9e5281bf Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Feb 2021 21:01:38 +0300 Subject: [PATCH 04/18] update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 733b890..6ddcb81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security -## [0.8.0] +## [0.8.1] ### Added - Ktor version to versions - Add sonatype publishing @@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - kaml ### Fixed +- Fix publishing load order for sonatype +- Fix root project readme ### Security From a871db0c15dbf87d88f2308a726695030a3d7fee Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Feb 2021 21:50:29 +0300 Subject: [PATCH 05/18] Fix readme again --- .../ru/mipt/npm/gradle/KScienceProjectPlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceReadmeExtension.kt | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 9e26f2d..c9280ee 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -128,7 +128,7 @@ open class KScienceProjectPlugin : Plugin { } val rootReadmeProperties: Map = - rootReadmeExtension.properties + ("modules" to modulesString) + rootReadmeExtension.actualizedProperties + ("modules" to modulesString) readmeFile.writeText( SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt index cf8c027..25b362c 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt @@ -46,30 +46,31 @@ class KScienceReadmeExtension(val project: Project) { features.add(Feature(id, description(), ref, name)) } - val properties: MutableMap Any?> = mutableMapOf( + private val properties: MutableMap Any?> = mutableMapOf( "name" to { project.name }, "group" to { project.group }, "version" to { project.version }, "features" to { featuresString() } ) - private fun getActualizedProperties() = properties.mapValues { (_, value) -> - value.invoke() - } + val actualizedProperties + get() = properties.mapValues { (_, value) -> + value.invoke() + } fun property(key: String, value: Any?) { properties[key] = { value } } fun propertyByTemplate(key: String, template: String) { - val actual = getActualizedProperties() + val actual = actualizedProperties properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } } internal val additionalFiles = ArrayList() fun propertyByTemplate(key: String, template: File) { - val actual = getActualizedProperties() + val actual = actualizedProperties properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } additionalFiles.add(template) } @@ -88,7 +89,7 @@ class KScienceReadmeExtension(val project: Project) { */ fun readmeString(): String? { return if (readmeTemplate.exists()) { - val actual = getActualizedProperties() + val actual = actualizedProperties SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() } else { null From 9c12501a5765ae4abfce98c5c6bc75ac5a18bebb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Feb 2021 10:43:15 +0300 Subject: [PATCH 06/18] Fix plugin loading order for publishing --- CHANGELOG.md | 1 + build.gradle.kts | 2 +- .../npm/gradle/KSciencePublishingPlugin.kt | 63 ++++++++++--------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ddcb81..567b28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed ### Fixed +- Plugin loading order for publishing ### Security diff --git a/build.gradle.kts b/build.gradle.kts index 4b5b363..1cb3b62 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.1" +version = "0.8.2" description = "Build tools for DataForge and kscience projects" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index d02563d..a0abdce 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -15,48 +15,46 @@ private fun Project.isSnapshot() = version.toString().contains("dev") || version open class KSciencePublishingPlugin : Plugin { - override fun apply(project: Project): Unit { - project.run { - if (plugins.findPlugin("maven-publish") == null) { - plugins.apply("maven-publish") - } - configure { - plugins.withId("org.jetbrains.kotlin.js") { - val kotlin = extensions.findByType()!! + override fun apply(project: Project): Unit = project.run { + if (plugins.findPlugin("maven-publish") == null) { + plugins.apply("maven-publish") + } - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) - } + configure { + plugins.withId("ru.mipt.npm.gradle.js") { + val kotlin = extensions.findByType()!! - publications { - create("js", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } + val sourcesJar: Jar by project.tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets["main"].kotlin) } - 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("js", MavenPublication::class) { + from(components["kotlin"]) + artifact(sourcesJar) } + } + } - publications { - create("jvm", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } + plugins.withId("ru.mipt.npm.gradle.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) } } } } project.afterEvaluate { - val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" val githubProject: String? by project val vcs = findProperty("vcs") as? String @@ -174,7 +172,8 @@ open class KSciencePublishingPlugin : Plugin { val sonatypePassword: String? by project val keyId: String? by project - val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey") + val signingKey: String? = + project.findProperty("signingKey") as? String ?: System.getenv("signingKey") val signingKeyPassphrase: String? by project if (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null) { @@ -212,3 +211,5 @@ open class KSciencePublishingPlugin : Plugin { } } } + + From 133736f00fee2dae128b452f017e4b1fd0943a4e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Feb 2021 13:22:41 +0300 Subject: [PATCH 07/18] Fix plugin loading order for publishing --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../mipt/npm/gradle/KScienceCommonPlugin.kt | 47 +-- .../npm/gradle/KSciencePublishingPlugin.kt | 319 +++++++++--------- 3 files changed, 192 insertions(+), 176 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a56324..442d913 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.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index d355726..8938426 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -20,11 +20,6 @@ open class KScienceCommonPlugin : Plugin { registerKScienceExtension() repositories.applyRepos() - // apply dokka for all projects - if (!plugins.hasPlugin("org.jetbrains.dokka")) { - plugins.apply("org.jetbrains.dokka") - } - //Configuration for K-JVM plugin pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { //logger.info("Applying KScience configuration for JVM project") @@ -43,6 +38,22 @@ open class KScienceCommonPlugin : Plugin { } } } + tasks.withType { + kotlinOptions { + useIR = true + jvmTarget = KScienceVersions.JVM_TARGET.toString() + } + } + + extensions.findByType()?.apply { + targetCompatibility = KScienceVersions.JVM_TARGET + } + + tasks.apply { + withType { + useJUnitPlatform() + } + } } pluginManager.withPlugin("org.jetbrains.kotlin.js") { @@ -123,25 +134,23 @@ open class KScienceCommonPlugin : Plugin { (tasks.findByName("jsProcessResources") as? Copy)?.apply { fromJsDependencies("jsRuntimeClasspath") } - } - } - afterEvaluate { - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - } + extensions.findByType()?.apply { + targetCompatibility = KScienceVersions.JVM_TARGET + } - tasks.apply { - withType { - kotlinOptions { - useIR = true - jvmTarget = KScienceVersions.JVM_TARGET.toString() + tasks.apply { + withType { + useJUnitPlatform() } } - withType { - useJUnitPlatform() - } } } + + // apply dokka for all projects + if (!plugins.hasPlugin("org.jetbrains.dokka")) { + plugins.apply("org.jetbrains.dokka") + } + } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index a0abdce..9641a35 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -15,194 +15,201 @@ private fun Project.isSnapshot() = version.toString().contains("dev") || version open class KSciencePublishingPlugin : Plugin { - override fun apply(project: Project): Unit = project.run { - if (plugins.findPlugin("maven-publish") == null) { - plugins.apply("maven-publish") - } + override fun apply(project: Project): Unit { - configure { - plugins.withId("ru.mipt.npm.gradle.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) - } - } + //Add publishing plugin and new publications + project.run { + if (plugins.findPlugin("maven-publish") == null) { + plugins.apply("maven-publish") } - plugins.withId("ru.mipt.npm.gradle.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) - } - } - } - } - - project.afterEvaluate { - 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 { - val dokkaJar: Jar by tasks.creating(Jar::class) { - group = "documentation" - archiveClassifier.set("javadoc") - from(tasks.findByName("dokkaHtml")) - } + plugins.withId("ru.mipt.npm.gradle.js") { + val kotlin = extensions.findByType()!! - // 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) } + val sourcesJar: Jar by project.tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets["main"].kotlin) + } - 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=]/*Повторить предыдущую ссылку*/" - } + publications { + create("js", MavenPublication::class) { + from(components["kotlin"]) + artifact(sourcesJar) } } } - val githubUser: String? by project - val githubToken: String? by project + plugins.withId("ru.mipt.npm.gradle.jvm") { + val kotlin = extensions.findByType()!! - 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 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 spaceRepo: String? by project - val spaceUser: String? by project - val spaceToken: String? by project + //configure publications after everything is set in the root project + project.rootProject.afterEvaluate { + project.run { + 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 (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 - } - - } + configure { + val dokkaJar: Jar by tasks.creating(Jar::class) { + group = "documentation" + archiveClassifier.set("javadoc") + from(tasks.findByName("dokkaHtml")) } - } - val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" - val bintrayUser: String? by project - val bintrayApiKey: String? by project - val bintrayPublish: String? by project + // 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) } - val bintrayRepo = if (isSnapshot()) { - "dev" - } else { - findProperty("bintrayRepo") as? String - } + 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") + } - 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 + } + vcs?.let { + scm { + url.set(vcs) + tag.set(project.version.toString()) + //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" + } } } } - } - val sonatypePublish: String? by project - val sonatypeUser: String? by project - val sonatypePassword: String? by project + val githubUser: String? by project + val githubToken: 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 (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 + } + } + } + } - if (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null) { - val sonatypeRepo: String = if (isSnapshot()) { - "https://oss.sonatype.org/content/repositories/snapshots" + 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 { - "https://oss.sonatype.org/service/local/staging/deploy/maven2" + findProperty("bintrayRepo") as? String } - if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") + 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 + } + } + } } - extensions.configure("signing") { - if (!signingKey.isNullOrBlank()) { - //if key is provided, use it - @Suppress("UnstableApiUsage") - useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) - } // else use file signing - sign(publications) - } + val sonatypePublish: String? by project + val sonatypeUser: String? by project + val sonatypePassword: String? by project - repositories { - maven { - name = "sonatype" - url = uri(sonatypeRepo) - credentials { - username = sonatypeUser - password = sonatypePassword + 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 + } } } } From 48bf26e26ad23ad73e93253c429682861cec6365 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Feb 2021 13:28:16 +0300 Subject: [PATCH 08/18] Proper Jar import --- src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index 9641a35..52be9cf 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -4,7 +4,7 @@ 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.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import org.gradle.plugins.signing.SigningExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension From 1cc83e880333f8aafae769c409189411bbdbacfe Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Feb 2021 14:30:39 +0300 Subject: [PATCH 09/18] Adaptive native targets. --- CHANGELOG.md | 2 +- .../mipt/npm/gradle/KScienceNativePlugin.kt | 58 ++++++++++++------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 567b28e..bf29ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - +- Adaptive support for host OS in native ### Changed ### Deprecated diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 7486de0..2d6406d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -18,10 +18,21 @@ class KScienceNativePlugin : Plugin { } configure { - //deploy mode - linuxX64() - mingwX64() - macosX64() + val hostOs = System.getProperty("os.name") + + val isLinux = hostOs == "Linux" + val isMinGw = hostOs.startsWith("Windows") + val isMacOs = hostOs == "Mac OS X" + + if (isLinux || isMinGw) { + linuxX64() + } + if (isMinGw) { + mingwX64() + } + if (isMacOs) { + macosX64() + } sourceSets { val commonMain by getting @@ -35,28 +46,33 @@ class KScienceNativePlugin : Plugin { dependsOn(commonTest) } - val linuxX64Main by getting { - dependsOn(nativeMain) + if (isLinux) { + val linuxX64Main by getting { + dependsOn(nativeMain) + } + val linuxX64Test by getting { + dependsOn(nativeTest) + } } - val mingwX64Main by getting { - dependsOn(nativeMain) + if (isMinGw) { + val mingwX64Main by getting { + dependsOn(nativeMain) + } + + val mingwX64Test by getting { + dependsOn(nativeTest) + } } - val macosX64Main by getting { - dependsOn(nativeMain) - } + if (isMacOs) { + val macosX64Main by getting { + dependsOn(nativeMain) + } - val linuxX64Test by getting { - dependsOn(nativeTest) - } - - val mingwX64Test by getting { - dependsOn(nativeTest) - } - - val macosX64Test by getting { - dependsOn(nativeTest) + val macosX64Test by getting { + dependsOn(nativeTest) + } } } } From 8efae2ca4d689fb391377c7a9840b50dea898b48 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Feb 2021 16:53:15 +0300 Subject: [PATCH 10/18] Fix native and node hmpp --- build.gradle.kts | 2 +- .../mipt/npm/gradle/KScienceNativePlugin.kt | 52 +++++++------------ .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 40 +++++++------- 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1cb3b62..852dd65 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.2" +version = "0.8.3" description = "Build tools for DataForge and kscience projects" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 2d6406d..6080de4 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -1,12 +1,20 @@ package ru.mipt.npm.gradle +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.findPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +private fun KotlinMultiplatformExtension.sourceSets(configure: Action>): Unit = + (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("sourceSets", configure) class KScienceNativePlugin : Plugin { - override fun apply(target: Project) = target.run { + override fun apply(project: Project) = project.run { //Apply multiplatform plugin is not applied, apply it if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") @@ -35,45 +43,25 @@ class KScienceNativePlugin : Plugin { } sourceSets { - val commonMain by getting - val commonTest by getting + val commonMain = findByName("commonMain")!! + val commonTest = findByName("commonTest")!! - val nativeMain by creating { + val nativeMain = create("nativeMain").apply { dependsOn(commonMain) } - val nativeTest by creating { + val nativeTest = create("nativeTest").apply { dependsOn(commonTest) } - if (isLinux) { - val linuxX64Main by getting { - dependsOn(nativeMain) - } - val linuxX64Test by getting { - dependsOn(nativeTest) - } - } + findByName("linuxX64Main")?.dependsOn(nativeMain) + findByName("linuxX64Test")?.dependsOn(nativeTest) - if (isMinGw) { - val mingwX64Main by getting { - dependsOn(nativeMain) - } + findByName("mingwX64Main")?.dependsOn(nativeMain) + findByName("mingwX64Test")?.dependsOn(nativeTest) - val mingwX64Test by getting { - dependsOn(nativeTest) - } - } - - if (isMacOs) { - val macosX64Main by getting { - dependsOn(nativeMain) - } - - val macosX64Test by getting { - dependsOn(nativeTest) - } - } + findByName("macosX64Main")?.dependsOn(nativeMain) + findByName("macosX64Test")?.dependsOn(nativeTest) } } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index e1367bc..b321012 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -1,9 +1,17 @@ package ru.mipt.npm.gradle +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.findPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +private fun KotlinMultiplatformExtension.sourceSets(configure: Action>): Unit = + (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("sourceSets", configure) /** * Create a separate target for node @@ -24,38 +32,30 @@ class KScienceNodePlugin : Plugin { js(name = "node", compiler = IR) { nodejs() } - sourceSets { - val commonMain by getting - val commonTest by getting - val jsCommonMain by creating{ + sourceSets { + val commonMain = findByName("commonMain")!! + val commonTest = findByName("commonTest")!! + + val jsCommonMain = create("jsCommonMain").apply { dependsOn(commonMain) } - val jsCommonTest by creating{ + val jsCommonTest = create("jsCommonTest").apply { dependsOn(commonTest) } - val jsMain by getting{ - dependsOn(jsCommonMain) - } + findByName("jsMain")?.dependsOn(jsCommonMain) + findByName("jsTest")?.dependsOn(jsCommonTest) - val jsTest by getting{ - dependsOn(jsCommonTest) - } - - val nodeMain by creating { + findByName("nodeMain")?.apply { dependsOn(jsCommonMain) - dependencies{ + dependencies { api("org.jetbrains.kotlinx:kotlinx-nodejs:${KScienceVersions.kotlinxNodeVersion}") } } - - val nodeTest by creating { - dependsOn(jsCommonTest) - } + findByName("nodeTest")?.dependsOn(jsCommonMain) } } - } } \ No newline at end of file From bef27d1f6ab87d37739cd386057d855b76fe4c19 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 3 Mar 2021 19:54:59 +0300 Subject: [PATCH 11/18] Versions update and revise release tasks --- build.gradle.kts | 4 +- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 44 ++++++------------- .../npm/gradle/KSciencePublishingPlugin.kt | 26 ++++++++--- .../ru/mipt/npm/gradle/KScienceVersions.kt | 8 ++-- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 852dd65..12919b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.3" +version = "0.8.4" description = "Build tools for DataForge and kscience projects" @@ -22,7 +22,7 @@ repositories { } -val kotlinVersion = "1.4.30" +val kotlinVersion = "1.4.31" java { targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index c9280ee..c513d17 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -8,8 +8,6 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaTask -import kotlin.collections.component1 -import kotlin.collections.component2 @Suppress("unused") class KSciencePublishingExtension(val project: Project) { @@ -104,20 +102,24 @@ open class KScienceProjectPlugin : Plugin { outputs.file(readmeFile) doLast { - val projects = subprojects.associate { - it.name to it.extensions.findByType() - } +// val projects = subprojects.associate { +// val normalizedPath = it.path.replaceFirst(":","").replace(":","/") +// it.path.replace(":","/") to it.extensions.findByType() +// } if (rootReadmeExtension.readmeTemplate.exists()) { val modulesString = buildString { - projects.entries.forEach { (name, ext) -> + subprojects.forEach { subproject-> + val name = subproject.name + val path = subproject.path.replaceFirst(":","").replace(":","/") + val ext = subproject.extensions.findByType() appendln("
") - appendln("\n* ### [$name]($name)") + appendln("\n* ### [$name]($path)") if (ext != null) { appendln("> ${ext.description}") appendln(">\n> **Maturity**: ${ext.maturity}") - val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/") + val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$path/") if (featureString.isNotBlank()) { appendln(">\n> **Features:**") appendln(featureString) @@ -145,28 +147,10 @@ open class KScienceProjectPlugin : Plugin { val patchChangelog by tasks.getting - afterEvaluate { - val release by tasks.creating { - group = RELEASE_GROUP - description = "Publish development or production release based on version suffix" - dependsOn(generateReadme) - - 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("publish${publicationName}ToBintrayRepository")?.let { - dependsOn(it) - } - tasks.findByName("publish${publicationName}ToSpaceRepository")?.let { - dependsOn(it) - } - } + val release by tasks.creating { + group = RELEASE_GROUP + description = "Publish development or production release based on version suffix" + dependsOn(generateReadme) } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index 52be9cf..109b065 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -60,6 +60,8 @@ open class KSciencePublishingPlugin : Plugin { //configure publications after everything is set in the root project project.rootProject.afterEvaluate { + //root project release task + val release by tasks.getting project.run { val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm" val githubProject: String? by project @@ -182,12 +184,8 @@ open class KSciencePublishingPlugin : Plugin { 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 (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null && !isSnapshot()) { + val sonatypeRepo: String = "https://oss.sonatype.org/service/local/staging/deploy/maven2" if (plugins.findPlugin("signing") == null) { plugins.apply("signing") @@ -214,6 +212,22 @@ open class KSciencePublishingPlugin : Plugin { } } } + + + val publicationPlatform = project.findProperty("publication.platform") as? String + val publicationName = if (publicationPlatform == null) { + "AllPublications" + } else { + publicationPlatform.capitalize() + "Publication" + } + + tasks.findByName("publish${publicationName}ToSonatypeRepository")?.let { + release.dependsOn(it) + } + + tasks.findByName("publish${publicationName}ToSpaceRepository")?.let { + release.dependsOn(it) + } } } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index a494578..6e97280 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -6,18 +6,18 @@ import org.gradle.api.JavaVersion * Build constants */ object KScienceVersions { - const val kotlinVersion = "1.4.30" + const val kotlinVersion = "1.4.31" const val kotlinxNodeVersion = "0.0.7" - const val coroutinesVersion = "1.4.2" + const val coroutinesVersion = "1.4.3" const val serializationVersion = "1.1.0" const val atomicVersion = "0.15.1" - const val ktorVersion = "1.5.1" + const val ktorVersion = "1.5.2" const val htmlVersion = "0.7.2" val JVM_TARGET = JavaVersion.VERSION_11 object Serialization{ - const val xmlVersion = "0.81.0" + const val xmlVersion = "0.81.1" const val bsonVersion = "0.4.4" const val yamlKtVersion = "0.9.0" } From 7971335558ebc699098c1bed8019fd4fb3abdaaf Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 3 Mar 2021 20:01:46 +0300 Subject: [PATCH 12/18] Patch CHANGELOG.md --- CHANGELOG.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf29ad3..518294f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,15 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Adaptive support for host OS in native + ### Changed ### Deprecated ### Removed +### Fixed + +### Security + +## [0.8.4] +### Added +- Adaptive support for host OS in native +### Changed +- Kotlin 1.4.31 +- Coroutines 1.4.3 + +### Deprecated + +### Removed + ### Fixed - Plugin loading order for publishing +- Release task +- Readme generation for multi-module project ### Security From 76fd9dfa5743fc41ceb826a02a971cf423456771 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 3 Mar 2021 21:10:52 +0300 Subject: [PATCH 13/18] Css support --- CHANGELOG.md | 2 ++ .../ru/mipt/npm/gradle/KScienceCommonPlugin.kt | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 518294f..773efed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.8.4] ### Added - Adaptive support for host OS in native +- CSS support for JS targets + ### Changed - Kotlin 1.4.31 - Coroutines 1.4.3 diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index 8938426..f0b7490 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import ru.mipt.npm.gradle.internal.applyRepos -import ru.mipt.npm.gradle.internal.applySettings import ru.mipt.npm.gradle.internal.fromJsDependencies open class KScienceCommonPlugin : Plugin { @@ -62,7 +61,11 @@ open class KScienceCommonPlugin : Plugin { explicitApiWarning() js(IR) { - browser() + browser{ + commonWebpackConfig { + cssSupport.enabled = true + } + } } sourceSets["main"].apply { @@ -97,7 +100,11 @@ open class KScienceCommonPlugin : Plugin { } js(IR) { - browser() + browser{ + commonWebpackConfig { + cssSupport.enabled = true + } + } } sourceSets.invoke { From d673eb84ae009095a1103924160fbecf3759a409 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 3 Mar 2021 21:19:59 +0300 Subject: [PATCH 14/18] Fix imports --- src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index f0b7490..d3b1b65 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import ru.mipt.npm.gradle.internal.applyRepos +import ru.mipt.npm.gradle.internal.applySettings import ru.mipt.npm.gradle.internal.fromJsDependencies open class KScienceCommonPlugin : Plugin { From 8dcf45b8d5beaf8b2ebe7388da8f87e59833fb3b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 6 Mar 2021 20:50:17 +0300 Subject: [PATCH 15/18] Change publishing scheme --- CHANGELOG.md | 3 + build.gradle.kts | 2 +- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 59 +++-- .../npm/gradle/KSciencePublishingPlugin.kt | 229 +----------------- .../ru/mipt/npm/gradle/internal/common.kt | 5 +- .../ru/mipt/npm/gradle/internal/publishing.kt | 210 ++++++++++++++++ 6 files changed, 261 insertions(+), 247 deletions(-) create mode 100644 src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 773efed..9136fcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- Publishing repositories are explicit and defined in the top level project ### Deprecated +- Publishing plugin ### Removed +- Bintray publishing ### Fixed diff --git a/build.gradle.kts b/build.gradle.kts index 12919b7..e86d244 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.4" +version = "0.9.0-dev-1" description = "Build tools for DataForge and kscience projects" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index c513d17..73f036a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -8,29 +8,52 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaTask +import ru.mipt.npm.gradle.internal.addGithubPublishing +import ru.mipt.npm.gradle.internal.addSonatypePublishing +import ru.mipt.npm.gradle.internal.addSpacePublishing +import ru.mipt.npm.gradle.internal.setupPublication @Suppress("unused") class KSciencePublishingExtension(val project: Project) { - var vcs: String? by project.extra + private var initializedFlag = false - // github publishing - var githubOrg: String? by project.extra - var githubProject: String? by project.extra + fun setup(vcsUrl: String){ + project.setupPublication(vcsUrl) + initializedFlag = true + } - // Space publishing - var spaceRepo: String? by project.extra - var spaceUser: String? by project.extra - var spaceToken: String? by project.extra + /** + * github publishing + */ + fun github(githubProject: String, githubOrg: String = "mipt-npm") { + //automatically initialize vcs using github + if(!initializedFlag){ + setup("https://github.com/$githubOrg/$githubProject") + } + project.addGithubPublishing(githubOrg, githubProject) + } - // 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 + /** + * Space publishing + */ + fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven") { + require(initializedFlag){"The publishing is not set up use 'setup' method to do so"} + project.addSpacePublishing(spaceRepo) + } - // Sonatype publising - var sonatypeUser: String? by project.extra - var sonatypePassword: 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 + */ + fun sonatype(){ + require(initializedFlag){"The publishing is not set up use 'setup' method to do so"} + project.addSonatypePublishing() + } } @@ -110,9 +133,9 @@ open class KScienceProjectPlugin : Plugin { if (rootReadmeExtension.readmeTemplate.exists()) { val modulesString = buildString { - subprojects.forEach { subproject-> + subprojects.forEach { subproject -> val name = subproject.name - val path = subproject.path.replaceFirst(":","").replace(":","/") + val path = subproject.path.replaceFirst(":", "").replace(":", "/") val ext = subproject.extensions.findByType() appendln("
") appendln("\n* ### [$name]($path)") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt index 109b065..7946020 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -2,235 +2,16 @@ 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.api.tasks.bundling.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") +@Deprecated("To be replaced by maven-publish") open class KSciencePublishingPlugin : Plugin { - override fun apply(project: Project): Unit { - - //Add publishing plugin and new publications - project.run { - if (plugins.findPlugin("maven-publish") == null) { - plugins.apply("maven-publish") - } - - configure { - plugins.withId("ru.mipt.npm.gradle.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("ru.mipt.npm.gradle.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) - } - } - } - } - } - - //configure publications after everything is set in the root project - project.rootProject.afterEvaluate { - //root project release task - val release by tasks.getting - project.run { - 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 { - 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 && !isSnapshot()) { - val sonatypeRepo: String = "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 - } - } - } - } - } - - - val publicationPlatform = project.findProperty("publication.platform") as? String - val publicationName = if (publicationPlatform == null) { - "AllPublications" - } else { - publicationPlatform.capitalize() + "Publication" - } - - tasks.findByName("publish${publicationName}ToSonatypeRepository")?.let { - release.dependsOn(it) - } - - tasks.findByName("publish${publicationName}ToSpaceRepository")?.let { - release.dependsOn(it) - } - } + override fun apply(project: Project): Unit = project.run { + if (plugins.findPlugin("maven-publish") == null) { + plugins.apply("maven-publish") } } + } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt index ab26d38..21ca61d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -21,14 +21,11 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit { internal fun RepositoryHandler.applyRepos(): Unit { mavenCentral() + maven("https://repo.kotlin.link") maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlin-dev") maven("https://kotlin.bintray.com/kotlinx") maven("https://kotlin.bintray.com/kotlin-js-wrappers/") - maven("https://dl.bintray.com/mipt-npm/kscience") - maven("https://dl.bintray.com/mipt-npm/dev") - maven("https://dl.bintray.com/mipt-npm/dataforge") - maven("https://repo.kotlin.link") } internal fun Copy.fromJsDependencies(configurationName: String) = project.afterEvaluate { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt new file mode 100644 index 0000000..9e3c310 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -0,0 +1,210 @@ +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.api.tasks.bundling.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.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String + ?: System.getenv(propertyName) + +private fun Project.requestProperty(propertyName: String): String = requestPropertyOrNull(propertyName) + ?: error("Property $propertyName not defined") + + +internal fun Project.setupPublication(vcs: String) = allprojects { + plugins.withId("maven-publish") { + configure { + + plugins.withId("ru.mipt.npm.gradle.js") { + val kotlin = extensions.findByType()!! + + val sourcesJar: Jar by tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(kotlin.sourceSets["main"].kotlin) + } + + publications { + create("js", MavenPublication::class) { + from(components["kotlin"]) + artifact(sourcesJar) + } + } + } + + plugins.withId("ru.mipt.npm.gradle.jvm") { + val kotlin = extensions.findByType()!! + + val sourcesJar: Jar by 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) + 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") + } + + } + scm { + url.set(vcs) + tag.set(project.version.toString()) + //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" + } + + } + } + } + } +} + +internal fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT") + +internal val Project.publicationTarget: String + get() { + val publicationPlatform = project.findProperty("publication.platform") as? String + return if (publicationPlatform == null) { + "AllPublications" + } else { + publicationPlatform.capitalize() + "Publication" + } + } + +internal fun Project.addGithubPublishing( + githubOrg: String, + githubProject: String +) { + val githubUser: String = requestProperty("publishing.github.user") + val githubToken: String = requestProperty("publishing.github.token") + + allprojects { + plugins.withId("maven-publish") { + configure { + logger.info("Adding github publishing to project [${project.name}]") + repositories { + maven { + name = "github" + url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/") + credentials { + username = githubUser + password = githubToken + } + } + } + } + val publicationTask = tasks.getByName("publish${publicationTarget}ToGithubRepository") + rootProject.tasks.findByName("release")?.dependsOn(publicationTask) + } + } +} + +internal fun Project.addSpacePublishing(spaceRepo: String) { + val spaceUser: String = requestProperty("publishing.space.user") + val spaceToken: String = requestProperty("publishing.space.token") + + allprojects { + plugins.withId("maven-publish") { + configure { + 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 publicationTask = tasks.getByName("publish${publicationTarget}ToSpaceRepository") + rootProject.tasks.findByName("release")?.dependsOn(publicationTask) + } + } +} + +internal fun Project.addSonatypePublishing() { + val sonatypeUser: String = requestProperty("publishing.sonatype.user") + val sonatypePassword: String = requestProperty("publishing.sonatype.password") + val signingId: String? = requestPropertyOrNull("publishing.signing.id") + + + allprojects { + plugins.withId("maven-publish") { + configure { + val sonatypeRepo: String = "https://oss.sonatype.org/service/local/staging/deploy/maven2" + + if (plugins.findPlugin("signing") == null) { + plugins.apply("signing") + } + extensions.configure("signing") { + if (!signingId.isNullOrBlank()) { + val signingKey: String = requestProperty("publishing.signing.key") + val signingPassphrase: String = requestProperty("publishing.signing.passPhrase") + + //if key is provided, use it + @Suppress("UnstableApiUsage") + useInMemoryPgpKeys(signingId, signingKey, signingPassphrase) + } // else use file signing + sign(publications) + } + + repositories { + maven { + name = "sonatype" + url = uri(sonatypeRepo) + credentials { + username = sonatypeUser + password = sonatypePassword + } + } + } + } + val publicationTask = tasks.getByName("publish${publicationTarget}ToSonatypeRepository") + rootProject.tasks.findByName("release")?.dependsOn(publicationTask) + } + } +} + +//internal val Project.bintrayPublish: Boolean +// get() = (findProperty("publishing.bintray.publish") as? String)?.toBoolean() ?: false +//internal val Project.bintrayOrg: String? get() = findProperty("publishing.bintray.org") as? String +//internal val Project.bintrayUser: String? get() = findProperty("publishing.bintray.user") as? String +//internal val Project.bintrayApiKey: String? get() = findProperty("publishing.bintray.apiKey") as? String From fd046394a452e66f94d1ef76f01c236e32edc1e0 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Mar 2021 09:16:21 +0300 Subject: [PATCH 16/18] Add system properties to avoid publishing --- src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt index 9e3c310..983ef1f 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -110,6 +110,8 @@ internal fun Project.addGithubPublishing( githubOrg: String, githubProject: String ) { + if (requestPropertyOrNull("publishing.github") == "false") return + val githubUser: String = requestProperty("publishing.github.user") val githubToken: String = requestProperty("publishing.github.token") @@ -135,6 +137,8 @@ internal fun Project.addGithubPublishing( } internal fun Project.addSpacePublishing(spaceRepo: String) { + if (requestPropertyOrNull("publishing.space") == "false") return + val spaceUser: String = requestProperty("publishing.space.user") val spaceToken: String = requestProperty("publishing.space.token") @@ -161,11 +165,12 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { } internal fun Project.addSonatypePublishing() { + if (requestPropertyOrNull("publishing.sonatype") == "false") return + val sonatypeUser: String = requestProperty("publishing.sonatype.user") val sonatypePassword: String = requestProperty("publishing.sonatype.password") val signingId: String? = requestPropertyOrNull("publishing.signing.id") - allprojects { plugins.withId("maven-publish") { configure { From eacdb132edd4cd872844948aca54908c0d73873d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Mar 2021 09:22:48 +0300 Subject: [PATCH 17/18] change publishing properties name --- CHANGELOG.md | 1 + build.gradle.kts | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9136fcf..4c38604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Publishing repositories are explicit and defined in the top level project +- Paths to publishing properties now use dot notation like `publishing.github.user` ### Deprecated - Publishing plugin diff --git a/build.gradle.kts b/build.gradle.kts index e86d244..f844d1e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ dependencies { implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.4.0") } -project.extensions.findByType()?.apply{ +project.extensions.findByType()?.apply { plugins { create("common") { id = "ru.mipt.npm.gradle.common" @@ -141,8 +141,8 @@ afterEvaluate { } val spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/mipt-npm/maven" - val spaceUser: String? by project - val spaceToken: String? by project + val spaceUser: String? = project.findProperty("publishing.space.user") as? String + val spaceToken: String? = project.findProperty("publishing.space.token") as? String if (spaceUser != null && spaceToken != null) { project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") @@ -159,8 +159,8 @@ afterEvaluate { } } - val sonatypeUser: String? by project - val sonatypePassword: String? by project + val sonatypeUser: String? = project.findProperty("publishing.sonatype.user") as? String + val sonatypePassword: String? = project.findProperty("publishing.sonatype.password") as? String if (sonatypeUser != null && sonatypePassword != null) { val sonatypeRepo: String = if (project.version.toString().contains("dev")) { From 4b902332868a1fd84b2eda7126dc3cc9c11e1b5a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Mar 2021 09:55:54 +0300 Subject: [PATCH 18/18] bump release --- CHANGELOG.md | 14 ++++++++++++++ build.gradle.kts | 2 +- .../ru/mipt/npm/gradle/internal/publishing.kt | 19 ++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c38604..5d0852f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.9.0] +### Added +- Skip sonatype publishing for dev versions + ### Changed - Publishing repositories are explicit and defined in the top level project - Paths to publishing properties now use dot notation like `publishing.github.user` diff --git a/build.gradle.kts b/build.gradle.kts index f844d1e..b645cc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.9.0-dev-1" +version = "0.9.0" description = "Build tools for DataForge and kscience projects" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt index 983ef1f..cec6a2b 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -110,7 +110,10 @@ internal fun Project.addGithubPublishing( githubOrg: String, githubProject: String ) { - if (requestPropertyOrNull("publishing.github") == "false") return + if (requestPropertyOrNull("publishing.github") == "false") { + logger.info("Skipping github publishing based on flag value") + return + } val githubUser: String = requestProperty("publishing.github.user") val githubToken: String = requestProperty("publishing.github.token") @@ -137,7 +140,10 @@ internal fun Project.addGithubPublishing( } internal fun Project.addSpacePublishing(spaceRepo: String) { - if (requestPropertyOrNull("publishing.space") == "false") return + if (requestPropertyOrNull("publishing.space") == "false") { + logger.info("Skipping space publishing based on flag value") + return + } val spaceUser: String = requestProperty("publishing.space.user") val spaceToken: String = requestProperty("publishing.space.token") @@ -165,7 +171,14 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { } internal fun Project.addSonatypePublishing() { - if (requestPropertyOrNull("publishing.sonatype") == "false") return + if(isSnapshot()){ + logger.info("Sonatype publishing skipped for dev version") + return + } + if (requestPropertyOrNull("publishing.sonatype") == "false") { + logger.info("Skipping sonatype publishing based on flag value") + return + } val sonatypeUser: String = requestProperty("publishing.sonatype.user") val sonatypePassword: String = requestProperty("publishing.sonatype.password")