diff --git a/CHANGELOG.md b/CHANGELOG.md index 74574b1..5d0852f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security -## [0.8.0] + +## [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` + +### Deprecated +- Publishing plugin + +### Removed +- Bintray publishing + +### Fixed + +### Security + +## [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 + +### Deprecated + +### Removed + +### Fixed +- Plugin loading order for publishing +- Release task +- Readme generation for multi-module project + +### Security + +## [0.8.1] ### Added - Ktor version to versions - Add sonatype publishing @@ -36,6 +75,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 diff --git a/build.gradle.kts b/build.gradle.kts index cede88e..b645cc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.8.0" +version = "0.9.0" 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 @@ -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")) { 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..d3b1b65 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") { @@ -51,7 +62,11 @@ open class KScienceCommonPlugin : Plugin { explicitApiWarning() js(IR) { - browser() + browser{ + commonWebpackConfig { + cssSupport.enabled = true + } + } } sourceSets["main"].apply { @@ -86,7 +101,11 @@ open class KScienceCommonPlugin : Plugin { } js(IR) { - browser() + browser{ + commonWebpackConfig { + cssSupport.enabled = true + } + } } sourceSets.invoke { @@ -123,25 +142,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/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 7486de0..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") @@ -18,46 +26,42 @@ 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 - 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) } - val linuxX64Main by getting { - dependsOn(nativeMain) - } + findByName("linuxX64Main")?.dependsOn(nativeMain) + findByName("linuxX64Test")?.dependsOn(nativeTest) - val mingwX64Main by getting { - dependsOn(nativeMain) - } + findByName("mingwX64Main")?.dependsOn(nativeMain) + findByName("mingwX64Test")?.dependsOn(nativeTest) - val macosX64Main by getting { - dependsOn(nativeMain) - } - - val linuxX64Test by getting { - dependsOn(nativeTest) - } - - val mingwX64Test by getting { - dependsOn(nativeTest) - } - - 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 diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 0a08997..73f036a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -8,30 +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 kotlin.collections.component1 -import kotlin.collections.component2 +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() + } } @@ -103,20 +125,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) @@ -126,12 +152,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.actualizedProperties + ("modules" to modulesString) readmeFile.writeText( SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate) @@ -148,28 +170,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 a7412aa..7946020 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishingPlugin.kt @@ -2,207 +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.jvm.tasks.Jar -import org.gradle.kotlin.dsl.* -import org.gradle.plugins.signing.SigningExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension - - -private fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT") +@Deprecated("To be replaced by maven-publish") open class KSciencePublishingPlugin : Plugin { - override fun apply(project: Project): Unit = project.afterEvaluate { + override fun apply(project: Project): Unit = 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" } - - configure { - plugins.withId("org.jetbrains.kotlin.js") { - val kotlin = extensions.findByType()!! - - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) - } - - publications { - create("js", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } - } - - plugins.withId("org.jetbrains.kotlin.jvm") { - val kotlin = extensions.findByType()!! - - val sourcesJar: Jar by project.tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(kotlin.sourceSets["main"].kotlin) - } - - publications { - create("jvm", MavenPublication::class) { - from(components["kotlin"]) - artifact(sourcesJar) - } - } - } - - val dokkaJar: Jar by tasks.creating(Jar::class) { - group = "documentation" - archiveClassifier.set("javadoc") - from(tasks.findByName("dokkaHtml")) - } - - // Process each publication we have in this project - publications.withType().forEach { publication -> - publication.artifact(dokkaJar) - publication.pom { - name.set(project.name) - description.set(project.description ?: project.name) - vcs?.let { url.set(vcs) } - - licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - developers { - developer { - id.set("MIPT-NPM") - name.set("MIPT nuclear physics methods laboratory") - organization.set("MIPT") - organizationUrl.set("http://npm.mipt.ru") - } - - } - vcs?.let { - scm { - url.set(vcs) - tag.set(project.version.toString()) - //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" - } - } - } - } - - val githubUser: String? by project - val githubToken: String? by project - - if (githubProject != null && githubUser != null && githubToken != null) { - project.logger.info("Adding github publishing to project [${project.name}]") - repositories { - maven { - name = "github" - url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/") - credentials { - username = githubUser - password = githubToken - } - } - } - } - - val spaceRepo: String? by project - val spaceUser: String? by project - val spaceToken: String? by project - - if (spaceRepo != null && spaceUser != null && spaceToken != null) { - project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") - repositories { - maven { - name = "space" - url = uri(spaceRepo!!) - credentials { - username = spaceUser - password = spaceToken - } - - } - } - } - - val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" - val bintrayUser: String? by project - val bintrayApiKey: String? by project - val bintrayPublish: String? by project - - val bintrayRepo = if (isSnapshot()) { - "dev" - } else { - findProperty("bintrayRepo") as? String - } - - val projectName = project.name - - if (bintrayPublish == "true" && bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) { - project.logger.info("Adding bintray publishing to project [$projectName]") - - repositories { - maven { - name = "bintray" - url = uri( - "https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1" - ) - credentials { - username = bintrayUser - password = bintrayApiKey - } - } - } - } - - val sonatypePublish: String? by project - val sonatypeUser: String? by project - val sonatypePassword: String? by project - - val keyId: String? by project - val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey") - val signingKeyPassphrase: String? by project - - if (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null) { - val sonatypeRepo: String = if (isSnapshot()) { - "https://oss.sonatype.org/content/repositories/snapshots" - } else { - "https://oss.sonatype.org/service/local/staging/deploy/maven2" - } - - if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") - } - - extensions.configure("signing") { - if (!signingKey.isNullOrBlank()) { - //if key is provided, use it - @Suppress("UnstableApiUsage") - useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) - } // else use file signing - sign(publications) - } - - repositories { - maven { - name = "sonatype" - url = uri(sonatypeRepo) - credentials { - username = sonatypeUser - password = sonatypePassword - } - } - } - } - } } + } + + diff --git a/src/main/kotlin/ru/mipt/npm/gradle/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 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" } 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..cec6a2b --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -0,0 +1,228 @@ +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 +) { + 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") + + 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) { + 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") + + 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() { + 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") + 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