From 852158c665455ee92c137eba597a1148db5928d5 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Wed, 21 Jul 2021 19:01:10 +0700 Subject: [PATCH 01/16] Fix dependencies of release task --- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index c163c3d..70568f3 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -27,6 +27,12 @@ class KSciencePublishingExtension(val project: Project) { } } + private fun linkPublicationsToReleaseTask(name: String) = project.afterEvaluate { + allTasks() + .filter { it.name == "publish${publicationTarget}To${name.capitalize()}Repository" } + .forEach { releaseTask?.dependsOn(it) } + } + /** * github publishing * @param publish include github packages in release publishing. By default - false @@ -38,15 +44,7 @@ class KSciencePublishingExtension(val project: Project) { } project.addGithubPublishing(githubOrg, githubProject) - - if (publish) - project.afterEvaluate { - allTasks() - .find { it.name == "publish${publicationTarget}ToGithubRepository" } - ?.let { publicationTask -> - releaseTask?.dependsOn(publicationTask) - } - } + if (publish) linkPublicationsToReleaseTask("github") } private val releaseTask by lazy { @@ -60,12 +58,7 @@ class KSciencePublishingExtension(val project: Project) { require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } project.addSpacePublishing(spaceRepo) - if (publish) - project.afterEvaluate { - allTasks() - .find { it.name == "publish${publicationTarget}ToSpaceRepository" } - ?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) } - } + if (publish) linkPublicationsToReleaseTask("space") } // // Bintray publishing @@ -81,12 +74,7 @@ class KSciencePublishingExtension(val project: Project) { require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } project.addSonatypePublishing() - if (publish) - project.afterEvaluate { - allTasks() - .find { it.name == "publish${publicationTarget}ToSonatypeRepository" } - ?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) } - } + if (publish) linkPublicationsToReleaseTask("sonatype") } } -- 2.34.1 From 3fa500f4510a6ad021c57cd8993e5025701192b6 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Fri, 6 Aug 2021 14:28:00 +0700 Subject: [PATCH 02/16] Fix typo --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index aebb8aa..403fa86 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } -[kotlin-jupyter-gradle] +[libraries.kotlin-jupyter-gradle] module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin" version.ref = "kotlin-jupyter" -- 2.34.1 From 4f49e24d61a721fb802b60fbcffd71a150fc7c80 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Sat, 7 Aug 2021 09:43:11 +0700 Subject: [PATCH 03/16] Make all AbstractDokkaTask depend on generateReadme --- src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 70568f3..26cfc32 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -11,7 +11,6 @@ import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.dokka.gradle.AbstractDokkaTask import org.jetbrains.dokka.gradle.DokkaPlugin -import org.jetbrains.dokka.gradle.DokkaTask import ru.mipt.npm.gradle.internal.* private fun Project.allTasks(): Set = allprojects.flatMapTo(HashSet()) { it.tasks } @@ -131,7 +130,8 @@ open class KScienceProjectPlugin : Plugin { } } } - tasks.withType { + + tasks.withType { dependsOn(generateReadme) } } -- 2.34.1 From dc2ff2efb31c352bf08e93eaf1fbea2839c2cb7f Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Sun, 8 Aug 2021 00:05:08 +0700 Subject: [PATCH 04/16] Publish a version catalog --- build.gradle.kts | 48 ++++-- gradle/libs.versions.toml | 154 +++++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ru/mipt/npm/gradle/KScienceExtension.kt | 5 + .../ru/mipt/npm/gradle/KScienceVersions.kt | 1 + 5 files changed, 184 insertions(+), 26 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 97c5cfd..09cb3c6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,15 +1,15 @@ plugins { + alias(libs.plugins.changelog) + alias(libs.plugins.dokka) `java-gradle-plugin` `kotlin-dsl` `maven-publish` signing - alias(libs.plugins.changelog) - alias(libs.plugins.dokka) + `version-catalog` } group = "ru.mipt.npm" -version = "0.10.2" - +version = libs.versions.tools.get() description = "Build tools for DataForge and kscience projects" changelog.version.set(project.version.toString()) @@ -78,29 +78,41 @@ gradlePlugin { } } +val sourcesJar by tasks.creating(Jar::class) { + archiveClassifier.set("sources") + from(sourceSets.named("main").get().allSource) +} + +val javadocsJar by tasks.creating(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + archiveClassifier.set("javadoc") + from(tasks.dokkaHtml) +} + +catalog.versionCatalog { + from(files("gradle/libs.versions.toml")) +} + afterEvaluate { publishing { val vcs = "https://github.com/mipt-npm/gradle-tools" - val sourcesJar by tasks.creating(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets.named("main").get().allSource) - } - - val javadocsJar by tasks.creating(Jar::class) { - group = "documentation" - archiveClassifier.set("javadoc") - from(tasks.dokkaHtml) - } - // Process each publication we have in this project - publications.filterIsInstance().forEach { publication -> - publication.apply { + publications { + create("catalog") { + from(components["versionCatalog"]) + this.artifactId = "version-catalog" + + pom { + name.set("version-catalog") + } + } + + withType { artifact(sourcesJar) artifact(javadocsJar) pom { - name.set(project.name) description.set(project.description) url.set(vcs) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 403fa86..f1037e9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,23 +4,163 @@ binary-compatibility-validator = "0.6.0" changelog = "1.2.1" dokka = "1.5.0" kotlin = "1.5.21" -kotlin-jupyter = "0.10.0-173" +kotlin-jupyter = "0.10.0-184" +kotlinx-benchmark = "0.3.1" +kotlinx-cli = "0.3.2" +kotlinx-collections-immutable = "0.3.4" +kotlinx-coroutines = "1.5.1" +kotlinx-datetime = "0.2.1" +kotlinx-html = "0.7.3" +kotlinx-knit = "0.2.3" +kotlinx-nodejs = "0.0.7" +kotlinx-serialization = "1.2.2" +ktor = "1.6.2" +tools = "0.10.2" +xmlutil = "0.82.0" +yamlkt = "0.10.0" [libraries] atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } +atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" } + +binary-compatibility-validator = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator" } + changelog-gradle = { module = "org.jetbrains.intellij.plugins:gradle-changelog-plugin", version.ref = "changelog" } + dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } + kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } -[libraries.kotlin-jupyter-gradle] -module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin" -version.ref = "kotlin-jupyter" +kotlin-jupyter-gradle = { module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin", version.ref = "kotlin-jupyter" } -[libraries.binary-compatibility-validator] -module = "org.jetbrains.kotlinx:binary-compatibility-validator" -version.ref = "binary-compatibility-validator" +kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" } + +kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" } + +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-debug = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-debug", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-reactive = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-reactor = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactor", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-rx3 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx3", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-javafx = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-javafx", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-jdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-slf4j = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-slf4j", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-play-services = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "kotlinx-coroutines" } + +kotlinx-cli = { module = "org.jetbrains.kotlinx:kotlinx-cli", version.ref = "kotlinx-cli" } + +kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } + +kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html", version.ref = "kotlinx-html" } + +kotlinx-knit = { module = "org.jetbrains.kotlinx:kotlinx-knit", version.ref = "kotlinx-knit" } + +kotlinx-nodejs = { module = "org.jetbrains.kotlinx:kotlinx-nodejs", version.ref = "kotlinx-nodejs" } + +kotlinx-serialization-cbor = { module = "org.jetbrains.kotlinx:kotlinx-serialization-cbor", version.ref = "kotlinx-serialization" } +kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" } +kotlinx-serialization-hocon = { module = "org.jetbrains.kotlinx:kotlinx-serialization-hocon", version.ref = "kotlinx-serialization" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } +kotlinx-serialization-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "kotlinx-serialization" } +kotlinx-serialization-properties = { module = "org.jetbrains.kotlinx:kotlinx-serialization-properties", version.ref = "kotlinx-serialization" } + +ktor-bom = { module = "io.ktor:ktor-bom", version.ref = "ktor" } +ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "ktor" } +ktor-client-apache = { module = "io.ktor:ktor-client-apache", version.ref = "ktor" } +ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } +ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } +ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" } +ktor-client-auth-basic = { module = "io.ktor:ktor-client-auth-basic", version.ref = "ktor" } +ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" } +ktor-client-encoding = { module = "io.ktor:ktor-client-encoding", version.ref = "ktor" } +ktor-client-json = { module = "io.ktor:ktor-client-json", version.ref = "ktor" } +ktor-client-gson = { module = "io.ktor:ktor-client-gson", version.ref = "ktor" } +ktor-client-jackson = { module = "io.ktor:ktor-client-jackson", version.ref = "ktor" } +ktor-client-serialization = { module = "io.ktor:ktor-client-serialization", version.ref = "ktor" } +ktor-client-logging = { module = "io.ktor:ktor-client-loggin", version.ref = "ktor" } +ktor-client-tracing = { module = "io.ktor:ktor-client-tracing", version.ref = "ktor" } +ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" } +ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" } +ktor-client-jetty = { module = "io.ktor:ktor-client-jetty", version.ref = "ktor" } +ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" } +ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" } +ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } +ktor-auth-jwt = { module = "io.ktor:ktor-auth-jwt", version.ref = "ktor" } +ktor-auth-ldap = { module = "io.ktor:ktor-auth-ldap", version.ref = "ktor" } +ktor-auth = { module = "io.ktor:ktor-auth", version.ref = "ktor" } +ktor-freemaker = { module = "io.ktor:ktor-freemaker", version.ref = "ktor" } +ktor-gson = { module = "io.ktor:ktor-gson", version.ref = "ktor" } +ktor-html-builder = { module = "io.ktor:ktor-html-builder", version.ref = "ktor" } +ktor-jackson = { module = "io.ktor:ktor-jackson", version.ref = "ktor" } +ktor-locations = { module = "io.ktor:ktor-locations", version.ref = "ktor" } +ktor-metrics-micrometer = { module = "io.ktor:ktor-metrics-micrometer", version.ref = "ktor" } +ktor-metrics = { module = "io.ktor:ktor-metrics", version.ref = "ktor" } +ktor-mustache = { module = "io.ktor:ktor-mustache", version.ref = "ktor" } +ktor-pebble = { module = "io.ktor:ktor-pebble", version.ref = "ktor" } +ktor-serialization = { module = "io.ktor:ktor-serialization", version.ref = "ktor" } +ktor-server-sessions = { module = "io.ktor:ktor-server-sessions", version.ref = "ktor" } +ktor-thymeleaf = { module = "io.ktor:ktor-thymeleaf", version.ref = "ktor" } +ktor-velocity = { module = "io.ktor:ktor-velocity", version.ref = "ktor" } +ktor-webjars = { module = "io.ktor:ktor-webjars", version.ref = "ktor" } +ktor-websockets = { module = "io.ktor:ktor-websockets", version.ref = "ktor" } +ktor-http = { module = "io.ktor:ktor-http", version.ref = "ktor" } +ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor" } +ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" } +ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" } +ktor-network-tls = { module = "io.ktor:ktor-network-tls", version.ref = "ktor" } +ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor" } +ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" } +ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" } +ktor-server-host-common = { module = "io.ktor:ktor-server-host-common", version.ref = "ktor" } +ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor" } +ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" } +ktor-server-servlet = { module = "io.ktor:ktor-server-servlet", version.ref = "ktor" } +ktor-server-test-host = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" } +ktor-server-tomcat = { module = "io.ktor:ktor-server-tomcat", version.ref = "ktor" } +ktor-test-dispatcher = { module = "io.ktor:ktor-test-dispatcher", version.ref = "ktor" } +ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor" } + +xmlutil-core = { module = "io.github.pdvrieze.xmlutil:core", version.ref = "xmlutil" } +xmlutil-ktor = { module = "io.github.pdvrieze.xmlutil:ktor", version.ref = "xmlutil" } +xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" } + +yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" } [plugins] changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } + dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } + +gradle-common = { id = "ru.mipt.npm.gradle.common", version.ref = "tools" } +gradle-project = { id = "ru.mipt.npm.gradle.project", version.ref = "tools" } +gradle-mpp = { id = "ru.mipt.npm.gradle.mpp", version.ref = "tools" } +gradle-jvm = { id = "ru.mipt.npm.gradle.jvm", version.ref = "tools" } +gradle-js = { id = "ru.mipt.npm.gradle.js", version.ref = "tools" } +gradle-native = { id = "ru.mipt.npm.gradle.native", version.ref = "tools" } +gradle-node = { id = "ru.mipt.npm.gradle.node", version.ref = "tools" } + +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-android-extensions = { id = "org.jetbrains.kotlin.android.extensions", version.ref = "kotlin" } +kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlin-native-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } +kotlin-plugin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" } +kotlin-plugin-jpa = { id = "org.jetbrains.kotlin.plugin.jpa", version.ref = "kotlin" } +kotlin-plugin-lombok = { id = "org.jetbrains.kotlin.plugin.lombok", version.ref = "kotlin" } +kotlin-plugin-noarg = { id = "org.jetbrains.kotlin.plugin.noarg", version.ref = "kotlin" } +kotlin-plugin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } +kotlin-plugin-scripting = { id = "org.jetbrains.kotlin.plugin.scripting", version.ref = "kotlin" } +kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +kotlin-plugin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } + +kotlin-jupyter-api = { id = "org.jetbrains.kotlin.jupyter.api", version.ref = "kotlin-jupyter" } + +kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cbfbc41..ffed3a2 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-7.2-rc-2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index dee6d7d..c03ced0 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -44,6 +44,7 @@ class KScienceExtension(val project: Project) { /** * Use coroutines-core with default version or [version] */ + @Deprecated("Use version catalog.") fun useCoroutines( version: String = KScienceVersions.coroutinesVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, @@ -57,6 +58,7 @@ class KScienceExtension(val project: Project) { /** * Use kotlinx-atmicfu plugin and library */ + @Deprecated("Use version catalog.") fun useAtomic( version: String = KScienceVersions.atomicVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, @@ -73,6 +75,7 @@ class KScienceExtension(val project: Project) { /** * Use core serialization library and configure targets */ + @Deprecated("Use version catalog.") fun useSerialization( version: String = KScienceVersions.serializationVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, @@ -106,6 +109,7 @@ class KScienceExtension(val project: Project) { /** * Add dependency on kotlinx-html library */ + @Deprecated("Use version catalog.") fun useHtml( version: String = KScienceVersions.htmlVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, @@ -119,6 +123,7 @@ class KScienceExtension(val project: Project) { /** * Use kotlinx-datetime library with default version or [version] */ + @Deprecated("Use version catalog.") fun useDateTime( version: String = KScienceVersions.dateTimeVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index b8acdb4..df7a1ba 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -5,6 +5,7 @@ import org.gradle.api.JavaVersion /** * Build constants */ +@Deprecated("Use version catalog.") object KScienceVersions { const val kotlinVersion = "1.5.21" const val kotlinxNodeVersion = "0.0.7" -- 2.34.1 From 02d2971b79233d8d9fc9886a4a97a938af7b18b4 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Wed, 11 Aug 2021 13:12:41 +0300 Subject: [PATCH 05/16] Refactor: explicit API, publishing extension, code style --- build.gradle.kts | 4 +- .../mipt/npm/gradle/KScienceCommonPlugin.kt | 22 ++- .../ru/mipt/npm/gradle/KScienceExtension.kt | 66 ++++----- .../ru/mipt/npm/gradle/KScienceJSPlugin.kt | 11 +- .../ru/mipt/npm/gradle/KScienceJVMPlugin.kt | 12 +- .../ru/mipt/npm/gradle/KScienceMPPlugin.kt | 9 +- .../mipt/npm/gradle/KScienceNativePlugin.kt | 69 ++++------ .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 18 +-- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 90 +++++++++---- .../npm/gradle/KScienceReadmeExtension.kt | 51 ++++--- .../ru/mipt/npm/gradle/KScienceVersions.kt | 28 ++-- .../mipt/npm/gradle/SerializationTargets.kt | 87 ++++++------ .../ru/mipt/npm/gradle/internal/common.kt | 7 +- .../mipt/npm/gradle/internal/dependencies.kt | 4 +- .../kotlin/ru/mipt/npm/gradle/internal/fx.kt | 5 +- .../ru/mipt/npm/gradle/internal/publishing.kt | 126 +++++++++--------- 16 files changed, 308 insertions(+), 301 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 97c5cfd..5c1a564 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,8 @@ repositories { java.targetCompatibility = JavaVersion.VERSION_11 +kotlin.explicitApiWarning() + dependencies { api(libs.kotlin.gradle) implementation(libs.atomicfu.gradle) @@ -158,7 +160,7 @@ afterEvaluate { } if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") + apply() } repositories.maven { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index 63d2c37..70b06c4 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -6,6 +6,7 @@ import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.Copy import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.* +import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension @@ -15,7 +16,7 @@ import ru.mipt.npm.gradle.internal.applySettings import ru.mipt.npm.gradle.internal.fromJsDependencies @Suppress("UNUSED_VARIABLE") -open class KScienceCommonPlugin : Plugin { +public open class KScienceCommonPlugin : Plugin { override fun apply(project: Project): Unit = project.run { //Common configuration registerKScienceExtension() @@ -50,10 +51,8 @@ open class KScienceCommonPlugin : Plugin { targetCompatibility = KScienceVersions.JVM_TARGET } - tasks.apply { - withType { - useJUnitPlatform() - } + tasks.withType { + useJUnitPlatform() } } @@ -112,7 +111,7 @@ open class KScienceCommonPlugin : Plugin { } } - sourceSets.invoke { + sourceSets { val commonMain by getting { dependencies { api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) @@ -128,7 +127,7 @@ open class KScienceCommonPlugin : Plugin { val jvmTest by getting { dependencies { implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:5.6.1") + implementation("org.junit.jupiter:junit-jupiter:5.7.2") } } val jsMain by getting @@ -155,18 +154,15 @@ open class KScienceCommonPlugin : Plugin { targetCompatibility = KScienceVersions.JVM_TARGET } - tasks.apply { - withType { - useJUnitPlatform() - } + tasks.withType { + useJUnitPlatform() } } } // apply dokka for all projects if (!plugins.hasPlugin("org.jetbrains.dokka")) { - plugins.apply("org.jetbrains.dokka") + apply() } - } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index dee6d7d..2b71104 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -1,8 +1,12 @@ package ru.mipt.npm.gradle +import kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin import org.gradle.api.Project import org.gradle.api.plugins.ApplicationPlugin +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension @@ -11,7 +15,7 @@ import ru.mipt.npm.gradle.internal.defaultPlatform import ru.mipt.npm.gradle.internal.useCommonDependency import ru.mipt.npm.gradle.internal.useFx -enum class FXModule(val artifact: String, vararg val dependencies: FXModule) { +public enum class FXModule(public val artifact: String, public vararg val dependencies: FXModule) { BASE("javafx-base"), GRAPHICS("javafx-graphics", BASE), CONTROLS("javafx-controls", GRAPHICS, BASE), @@ -21,30 +25,29 @@ enum class FXModule(val artifact: String, vararg val dependencies: FXModule) { WEB("javafx-web", CONTROLS, GRAPHICS, BASE) } -enum class FXPlatform(val id: String) { +public enum class FXPlatform(public val id: String) { WINDOWS("win"), LINUX("linux"), MAC("mac") } -enum class DependencyConfiguration { +public enum class DependencyConfiguration { API, IMPLEMENTATION, - COMPILE_ONLY + COMPILE_ONLY, } -enum class DependencySourceSet(val setName: String, val suffix: String) { +public enum class DependencySourceSet(public val setName: String, public val suffix: String) { MAIN("main", "Main"), TEST("test", "Test") } -class KScienceExtension(val project: Project) { - +public class KScienceExtension(public val project: Project) { /** * Use coroutines-core with default version or [version] */ - fun useCoroutines( + public fun useCoroutines( version: String = KScienceVersions.coroutinesVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.API, @@ -55,14 +58,14 @@ class KScienceExtension(val project: Project) { ) /** - * Use kotlinx-atmicfu plugin and library + * Use kotlinx-atomicfu plugin and library */ - fun useAtomic( + public fun useAtomic( version: String = KScienceVersions.atomicVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION, ): Unit = project.run { - plugins.apply("kotlinx-atomicfu") + apply() useCommonDependency( "org.jetbrains.kotlinx:atomicfu:$version", dependencySourceSet = sourceSet, @@ -73,13 +76,13 @@ class KScienceExtension(val project: Project) { /** * Use core serialization library and configure targets */ - fun useSerialization( + public fun useSerialization( version: String = KScienceVersions.serializationVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.API, block: SerializationTargets.() -> Unit = {}, ): Unit = project.run { - plugins.apply("org.jetbrains.kotlin.plugin.serialization") + apply("org.jetbrains.kotlin.plugin.serialization") val artifactName = if (version.startsWith("0")) { "kotlinx-serialization-runtime" } else { @@ -90,23 +93,23 @@ class KScienceExtension(val project: Project) { dependencySourceSet = sourceSet, dependencyConfiguration = configuration ) - SerializationTargets(sourceSet, configuration).apply(block) + SerializationTargets(sourceSet, configuration).block() } /** * Add platform-specific JavaFX dependencies with given list of [FXModule]s */ - fun useFx( + public fun useFx( vararg modules: FXModule, configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, version: String = "11", platform: FXPlatform = defaultPlatform, - ) = project.useFx(modules.toList(), configuration, version, platform) + ): Unit = project.useFx(modules.toList(), configuration, version, platform) /** * Add dependency on kotlinx-html library */ - fun useHtml( + public fun useHtml( version: String = KScienceVersions.htmlVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.API, @@ -119,35 +122,33 @@ class KScienceExtension(val project: Project) { /** * Use kotlinx-datetime library with default version or [version] */ - fun useDateTime( + public fun useDateTime( version: String = KScienceVersions.dateTimeVersion, sourceSet: DependencySourceSet = DependencySourceSet.MAIN, configuration: DependencyConfiguration = DependencyConfiguration.API, - ) { - project.useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-datetime:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } + ): Unit = project.useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-datetime:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration + ) /** * Apply jupyter plugin */ - fun useJupyter() { - project.plugins.apply("org.jetbrains.kotlin.jupyter.api") + public fun useJupyter() { + project.apply("org.jetbrains.kotlin.jupyter.api") } /** * Mark this module as an application module. JVM application should be enabled separately */ - fun application() { + public fun application() { project.extensions.findByType()?.apply { explicitApi = null } project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - project.plugins.apply(ApplicationPlugin::class.java) + project.apply() } project.extensions.findByType()?.apply { @@ -160,8 +161,9 @@ class KScienceExtension(val project: Project) { js { binaries.executable() } - targets.filterIsInstance().forEach { - it.binaries.executable() + + targets.withType { + binaries.executable() } } } @@ -171,4 +173,4 @@ internal fun Project.registerKScienceExtension() { if (extensions.findByType() == null) { extensions.add("kscience", KScienceExtension(this)) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index 75de0f4..b44574a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -4,13 +4,14 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -open class KScienceJSPlugin : Plugin { +public open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (plugins.findPlugin("org.jetbrains.kotlin.js") == null) { - pluginManager.apply("org.jetbrains.kotlin.js") + if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) { + apply("org.jetbrains.kotlin.js") } else { logger.info("Kotlin JS plugin is already present") } - plugins.apply(KScienceCommonPlugin::class) + + apply() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index f496817..fcfccf9 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -4,13 +4,13 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -open class KScienceJVMPlugin : Plugin { +public open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (plugins.findPlugin("org.jetbrains.kotlin.jvm") == null) { - pluginManager.apply("org.jetbrains.kotlin.jvm") - } else { + if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) + apply("org.jetbrains.kotlin.jvm") + else logger.info("Kotlin JVM plugin is already present") - } - plugins.apply(KScienceCommonPlugin::class) + + apply() } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index 167d9b9..c4a39f1 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -4,13 +4,14 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -open class KScienceMPPlugin : Plugin { +public open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { - pluginManager.apply("org.jetbrains.kotlin.multiplatform") + if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { + apply("org.jetbrains.kotlin.multiplatform") } else { logger.info("Kotlin MPP plugin is already present") } - plugins.apply(KScienceCommonPlugin::class) + + apply() } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 6080de4..12ce3c8 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -1,68 +1,57 @@ 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.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.findPlugin +import org.gradle.kotlin.dsl.* 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(project: Project) = project.run { +public class KScienceNativePlugin : Plugin { + override fun apply(project: Project): Unit = project.run { //Apply multiplatform plugin is not applied, apply it - if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { + if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - pluginManager.apply("org.jetbrains.kotlin.multiplatform") + apply("org.jetbrains.kotlin.multiplatform") } - if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { + + if (!plugins.hasPlugin(KScienceCommonPlugin::class)) { logger.info("KScience plugin is not resolved. Adding it automatically") - pluginManager.apply(KScienceCommonPlugin::class) + apply() } configure { - 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() - } + val nativeTargets = setOf( + linuxX64(), + mingwX64(), + macosX64(), + ) sourceSets { val commonMain = findByName("commonMain")!! val commonTest = findByName("commonTest")!! - val nativeMain = create("nativeMain").apply { + val nativeMain by creating { dependsOn(commonMain) } - val nativeTest = create("nativeTest").apply { + val nativeTest by creating { + dependsOn(nativeMain) dependsOn(commonTest) } - findByName("linuxX64Main")?.dependsOn(nativeMain) - findByName("linuxX64Test")?.dependsOn(nativeTest) + configure(nativeTargets) { + compilations["main"]?.apply { + configure(kotlinSourceSets) { + dependsOn(nativeMain) + } + } - findByName("mingwX64Main")?.dependsOn(nativeMain) - findByName("mingwX64Test")?.dependsOn(nativeTest) - - findByName("macosX64Main")?.dependsOn(nativeMain) - findByName("macosX64Test")?.dependsOn(nativeTest) + compilations["test"]?.apply { + configure(kotlinSourceSets) { + dependsOn(nativeTest) + } + } + } } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index b321012..0e3e0cc 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -1,31 +1,27 @@ 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.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.findPlugin +import org.gradle.kotlin.dsl.invoke 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 */ -class KScienceNodePlugin : Plugin { - override fun apply(target: Project) = target.run { +public class KScienceNodePlugin : Plugin { + override fun apply(target: Project): Unit = target.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") - pluginManager.apply("org.jetbrains.kotlin.multiplatform") + apply("org.jetbrains.kotlin.multiplatform") } + if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { logger.info("KScience plugin is not resolved. Adding it automatically") - pluginManager.apply(KScienceCommonPlugin::class) + apply() } configure { @@ -58,4 +54,4 @@ class KScienceNodePlugin : Plugin { } } } -} \ 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 70568f3..23bde44 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -17,13 +17,41 @@ import ru.mipt.npm.gradle.internal.* private fun Project.allTasks(): Set = allprojects.flatMapTo(HashSet()) { it.tasks } @Suppress("unused") -class KSciencePublishingExtension(val project: Project) { - private var initializedFlag = false +public class KSciencePublishingExtension(public val project: Project) { + private var isVcsInitialized = false - fun vcs(vcsUrl: String) { - if (!initializedFlag) { - project.setupPublication(vcsUrl) - initializedFlag = true + @Deprecated("Use git function and report an issue if other VCS is used.") + public fun vcs(vcsUrl: String) { + if (!isVcsInitialized) { + project.setupPublication { + url.set(vcsUrl) + scm { url.set(vcsUrl) } + } + + isVcsInitialized = true + } + } + + /** + * Configures Git repository for the publication. + * + * @param vcsUrl URL of the repository's web interface. + * @param connectionUrl URL of the Git repository. + * @param developerConnectionUrl URL of the Git repository for developers. + */ + public fun git(vcsUrl: String, connectionUrl: String? = null, developerConnectionUrl: String? = connectionUrl) { + if (!isVcsInitialized) { + project.setupPublication { + url.set(vcsUrl) + + scm { + url.set(vcsUrl) + connectionUrl?.let { connection.set("scm:git:$it") } + developerConnectionUrl?.let { developerConnection.set("scm:git:$it") } + } + } + + isVcsInitialized = true } } @@ -34,17 +62,19 @@ class KSciencePublishingExtension(val project: Project) { } /** - * github publishing - * @param publish include github packages in release publishing. By default - false + * Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing. + * + * @param githubProject the GitHub project. + * @param githubOrg the GitHub user or organization. + * @param released whether publish packages in the `release` task to the GitHub repository. */ - fun github(githubProject: String, githubOrg: String = "mipt-npm", publish: Boolean = false) { - //automatically initialize vcs using github - if (!initializedFlag) { - vcs("https://github.com/$githubOrg/$githubProject") - } + public fun github(githubProject: String, githubOrg: String = "mipt-npm", released: Boolean = false, published: Boolean = true) { + // Automatically initialize VCS using GitHub + if (!isVcsInitialized) + git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") - project.addGithubPublishing(githubOrg, githubProject) - if (publish) linkPublicationsToReleaseTask("github") + if (published) project.addGithubPublishing(githubOrg, githubProject) + if (released) linkPublicationsToReleaseTask("github") } private val releaseTask by lazy { @@ -52,13 +82,16 @@ class KSciencePublishingExtension(val project: Project) { } /** - * Space publishing + * Adds Space Packages Maven repository to publishing. + * + * @param spaceRepo the repository URL. + * @param released whether publish packages in the `release` task to the Space repository. */ - fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", publish: Boolean = false) { - require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } + public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", released: Boolean = false) { + require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } project.addSpacePublishing(spaceRepo) - if (publish) linkPublicationsToReleaseTask("space") + if (released) linkPublicationsToReleaseTask("space") } // // Bintray publishing @@ -68,20 +101,23 @@ class KSciencePublishingExtension(val project: Project) { // var bintrayRepo: String? by project.extra /** - * Sonatype publishing + * Adds Sonatype Maven repository to publishing. + * + * @param released whether publish packages in the `release` task to the Sonatype repository. */ - fun sonatype(publish: Boolean = true) { - require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } + public fun sonatype(released: Boolean = true) { + require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } project.addSonatypePublishing() - if (publish) linkPublicationsToReleaseTask("sonatype") + if (released) linkPublicationsToReleaseTask("sonatype") } } /** - * Apply extension and repositories + * Applies third-party plugins (Dokka, Changelog, binary compatibility validator); configures Maven publishing, README + * generation. */ -open class KScienceProjectPlugin : Plugin { +public open class KScienceProjectPlugin : Plugin { override fun apply(target: Project): Unit = target.run { apply() @@ -219,7 +255,7 @@ open class KScienceProjectPlugin : Plugin { } } - companion object { - const val RELEASE_GROUP = "release" + public companion object { + public const val RELEASE_GROUP: String = "release" } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt index 874a166..4edb9ca 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt @@ -3,10 +3,10 @@ package ru.mipt.npm.gradle import groovy.text.SimpleTemplateEngine import kotlinx.validation.ApiValidationExtension import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.* import java.io.File -enum class Maturity { +public enum class Maturity { PROTOTYPE, EXPERIMENTAL, DEVELOPMENT, @@ -14,16 +14,17 @@ enum class Maturity { } -class KScienceReadmeExtension(val project: Project) { - var description: String = project.description ?: "" - var maturity: Maturity = Maturity.EXPERIMENTAL +public class KScienceReadmeExtension(public val project: Project) { + public var description: String = project.description ?: "" + + public var maturity: Maturity = Maturity.EXPERIMENTAL set(value) { field = value val projectName = project.name if (value == Maturity.EXPERIMENTAL || value == Maturity.PROTOTYPE) { project.rootProject.run { plugins.withId("org.jetbrains.kotlinx.binary-compatibility-validator") { - extensions.getByType().apply { + extensions.findByType()?.apply { project.logger.warn("$value project $projectName is excluded from API validation") ignoredProjects.add(projectName) } @@ -32,18 +33,18 @@ class KScienceReadmeExtension(val project: Project) { } } - var readmeTemplate: File = project.file("docs/README-TEMPLATE.md") + public var readmeTemplate: File = project.file("docs/README-TEMPLATE.md") - data class Feature(val id: String, val description: String, val ref: String?, val name: String = id) + public data class Feature(val id: String, val description: String, val ref: String?, val name: String = id) - val features: MutableList = ArrayList() + public val features: MutableList = ArrayList() - @Deprecated("Use lambda builder instead") - fun feature(id: String, description: String, ref: String? = null, name: String = id) { + @Deprecated("Use lambda builder instead.") + public fun feature(id: String, description: String, ref: String? = null, name: String = id) { features += Feature(id, description, ref, name) } - fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) { + public fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) { features += Feature(id, description(), ref, name) } @@ -54,25 +55,25 @@ class KScienceReadmeExtension(val project: Project) { "features" to { featuresString() } ) - val actualizedProperties + public val actualizedProperties: Map get() = properties.mapValues { (_, value) -> value() } - fun property(key: String, value: Any?) { + public fun property(key: String, value: Any?) { properties[key] = { value } } - fun property(key: String, value: () -> Any?) { + public fun property(key: String, value: () -> Any?) { properties[key] = value } - fun propertyByTemplate(key: String, template: String) { + public fun propertyByTemplate(key: String, template: String) { val actual = actualizedProperties properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } } internal val additionalFiles = ArrayList() - fun propertyByTemplate(key: String, template: File) { + public fun propertyByTemplate(key: String, template: File) { val actual = actualizedProperties properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } additionalFiles += template @@ -81,7 +82,7 @@ class KScienceReadmeExtension(val project: Project) { /** * Generate a markdown string listing features */ - fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { + public fun featuresString(itemPrefix: String = " - ", pathPrefix: String = ""): String = buildString { features.forEach { appendLine("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") } @@ -90,12 +91,10 @@ class KScienceReadmeExtension(val project: Project) { /** * Generate a readme string from the stub */ - fun readmeString(): String? { - return if (readmeTemplate.exists()) { - val actual = actualizedProperties - SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() - } else { - null - } + public fun readmeString(): String? = if (readmeTemplate.exists()) { + val actual = actualizedProperties + SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() + } else { + null } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index b8acdb4..84002fe 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -5,21 +5,21 @@ import org.gradle.api.JavaVersion /** * Build constants */ -object KScienceVersions { - const val kotlinVersion = "1.5.21" - const val kotlinxNodeVersion = "0.0.7" - const val coroutinesVersion = "1.5.1" - const val serializationVersion = "1.2.2" - const val atomicVersion = "0.16.2" - const val ktorVersion = "1.6.1" - const val htmlVersion = "0.7.3" - const val dateTimeVersion = "0.2.1" - const val jsBom = "0.0.1-pre.216-kotlin-1.5.20" +public object KScienceVersions { + public const val kotlinVersion: String = "1.5.21" + public const val kotlinxNodeVersion: String = "0.0.7" + public const val coroutinesVersion: String = "1.5.1" + public const val serializationVersion: String = "1.2.2" + public const val atomicVersion: String = "0.16.2" + public const val ktorVersion: String = "1.6.1" + public const val htmlVersion: String = "0.7.3" + public const val dateTimeVersion: String = "0.2.1" + public const val jsBom: String = "0.0.1-pre.216-kotlin-1.5.20" - val JVM_TARGET = JavaVersion.VERSION_11 + public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 - object Serialization{ - const val xmlVersion = "0.82.0" - const val yamlKtVersion = "0.10.0" + public object Serialization { + public const val xmlVersion: String = "0.82.0" + public const val yamlKtVersion: String = "0.10.0" } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt b/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt index 62873c0..1ef2351 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/SerializationTargets.kt @@ -3,58 +3,47 @@ package ru.mipt.npm.gradle import org.gradle.api.Project import ru.mipt.npm.gradle.internal.useCommonDependency -class SerializationTargets( - val sourceSet: DependencySourceSet, - val configuration: DependencyConfiguration +public class SerializationTargets( + public val sourceSet: DependencySourceSet, + public val configuration: DependencyConfiguration, ) { + public fun Project.json( + version: String = KScienceVersions.serializationVersion, + ): Unit = useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-json:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration, + ) - fun Project.json( - version: String = KScienceVersions.serializationVersion - ) { - useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-serialization-json:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } + public fun Project.cbor( + version: String = KScienceVersions.serializationVersion, + ): Unit = useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration, + ) - fun Project.cbor( - version: String = KScienceVersions.serializationVersion - ) { - useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } + public fun Project.protobuf( + version: String = KScienceVersions.serializationVersion, + ): Unit = useCommonDependency( + "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration, + ) - fun Project.protobuf( - version: String = KScienceVersions.serializationVersion - ) { - useCommonDependency( - "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } + public fun Project.xml( + version: String = KScienceVersions.Serialization.xmlVersion, + ): Unit = useCommonDependency( + "io.github.pdvrieze.xmlutil:serialization:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration, + ) - fun Project.xml( - version: String = KScienceVersions.Serialization.xmlVersion - ) { - useCommonDependency( - "io.github.pdvrieze.xmlutil:serialization:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } - - fun Project.yamlKt( - version: String = KScienceVersions.Serialization.yamlKtVersion - ) { - useCommonDependency( - "net.mamoe.yamlkt:yamlkt:$version", - dependencySourceSet = sourceSet, - dependencyConfiguration = configuration - ) - } + public fun Project.yamlKt( + version: String = KScienceVersions.Serialization.yamlKtVersion, + ): Unit = useCommonDependency( + "net.mamoe.yamlkt:yamlkt:$version", + dependencySourceSet = sourceSet, + dependencyConfiguration = configuration, + ) } 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 07b01e8..f4d8096 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -11,7 +11,7 @@ import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder -internal fun LanguageSettingsBuilder.applySettings(): Unit { +internal fun LanguageSettingsBuilder.applySettings() { languageVersion = "1.5" apiVersion = "1.5" progressiveMode = true @@ -23,7 +23,7 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit { useExperimentalAnnotation("kotlin.js.ExperimentalJsExport") } -internal fun RepositoryHandler.applyRepos(): Unit { +internal fun RepositoryHandler.applyRepos() { mavenCentral() maven("https://repo.kotlin.link") } @@ -50,8 +50,7 @@ internal fun Copy.fromJsDependencies(configurationName: String) = project.run { } } - -fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){ +internal fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){ js { binaries.executable() browser { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/dependencies.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/dependencies.kt index eaf260b..9280846 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/dependencies.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/dependencies.kt @@ -87,7 +87,6 @@ internal fun Project.useCommonDependency( } } - withPlugin("org.jetbrains.kotlin.jvm") { configure { sourceSets.findByName(dependencySourceSet.setName)?.apply { @@ -102,6 +101,7 @@ internal fun Project.useCommonDependency( } } } + withPlugin("org.jetbrains.kotlin.js") { configure { sourceSets.findByName(dependencySourceSet.setName)?.apply { @@ -116,4 +116,4 @@ internal fun Project.useCommonDependency( } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/mipt/npm/gradle/internal/fx.kt b/src/main/kotlin/ru/mipt/npm/gradle/internal/fx.kt index 83c07df..3420cb3 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/fx.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/fx.kt @@ -2,6 +2,7 @@ package ru.mipt.npm.gradle.internal import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.findByType import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -10,7 +11,7 @@ import ru.mipt.npm.gradle.DependencyConfiguration import ru.mipt.npm.gradle.FXModule import ru.mipt.npm.gradle.FXPlatform -val defaultPlatform: FXPlatform = when { +internal val defaultPlatform: FXPlatform = when { Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX @@ -58,4 +59,4 @@ internal fun Project.useFx( } } } -} \ No newline at end of file +} 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 94eccc8..7185bec 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -2,10 +2,12 @@ package ru.mipt.npm.gradle.internal import org.gradle.api.Project import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPom 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.gradle.plugins.signing.SigningPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension @@ -16,27 +18,27 @@ private fun Project.requestProperty(propertyName: String): String = requestPrope ?: error("Property $propertyName not defined") -internal fun Project.setupPublication(vcs: String) = allprojects { +internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit = {}) = allprojects { plugins.withId("maven-publish") { configure { plugins.withId("org.jetbrains.kotlin.js") { val kotlin: KotlinJsProjectExtension = extensions.findByType()!! - val sourcesJar: Jar by tasks.creating(Jar::class) { + val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") - kotlin.sourceSets.forEach{ - from(it.kotlin) + + kotlin.sourceSets.all { + from(kotlin) } } afterEvaluate { - publications { - create("js", MavenPublication::class) { - kotlin.js().components.forEach { - from(it) - } - artifact(sourcesJar) + publications.create("js") { + kotlin.js().components.forEach { + from(it) } + + artifact(sourcesJar) } } } @@ -44,24 +46,23 @@ internal fun Project.setupPublication(vcs: String) = allprojects { plugins.withId("org.jetbrains.kotlin.jvm") { val kotlin = extensions.findByType()!! - val sourcesJar: Jar by tasks.creating(Jar::class) { + val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") - kotlin.sourceSets.forEach{ + kotlin.sourceSets.forEach { from(it.kotlin) } } - publications { - create("jvm", MavenPublication::class) { - kotlin.target.components.forEach { - from(it) - } - artifact(sourcesJar) + publications.create("jvm") { + kotlin.target.components.forEach { + from(it) } + + artifact(sourcesJar) } } - val dokkaJar: Jar by tasks.creating(Jar::class) { + val dokkaJar by tasks.creating(Jar::class) { group = "documentation" archiveClassifier.set("javadoc") from(tasks.findByName("dokkaHtml")) @@ -69,35 +70,35 @@ internal fun Project.setupPublication(vcs: String) = allprojects { // Process each publication we have in this project afterEvaluate { - publications.withType().forEach { publication -> - publication.artifact(dokkaJar) - publication.pom { + publications.withType { + artifact(dokkaJar) + + 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") + url.set("https://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") + organizationUrl.set("https://npm.mipt.ru") } - } + scm { - url.set(vcs) tag.set(project.version.toString()) - //developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/" } + mavenPomConfiguration() } } } @@ -105,7 +106,7 @@ internal fun Project.setupPublication(vcs: String) = allprojects { } } -internal fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT") +internal fun Project.isSnapshot() = "dev" in version.toString() || version.toString().endsWith("SNAPSHOT") internal val Project.publicationTarget: String get() { @@ -137,14 +138,14 @@ internal fun Project.addGithubPublishing( 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 - } + + repositories.maven { + name = "github" + url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/") + + credentials { + username = githubUser + password = githubToken } } } @@ -157,6 +158,7 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { logger.info("Skipping github publishing because publishing is disabled") return } + if (requestPropertyOrNull("publishing.space") == "false") { logger.info("Skipping space publishing because `publishing.space == false`") return @@ -169,15 +171,14 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { 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 - } + repositories.maven { + name = "space" + url = uri(spaceRepo) + + credentials { + username = spaceUser + password = spaceToken } } } @@ -186,14 +187,16 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { } internal fun Project.addSonatypePublishing() { - if(requestPropertyOrNull("publishing.enabled")!="true"){ + if (requestPropertyOrNull("publishing.enabled") != "true") { logger.info("Skipping github publishing because publishing is disabled") return } + if (isSnapshot()) { logger.info("Sonatype publishing skipped for dev version") return } + if (requestPropertyOrNull("publishing.sonatype") == "false") { logger.info("Skipping sonatype publishing because `publishing.sonatype == false`") return @@ -206,40 +209,33 @@ internal fun Project.addSonatypePublishing() { allprojects { plugins.withId("maven-publish") { configure { - val sonatypeRepo: String = "https://oss.sonatype.org/service/local/staging/deploy/maven2" + val sonatypeRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2" - if (plugins.findPlugin("signing") == null) { - plugins.apply("signing") + if (!plugins.hasPlugin("signing") ) { + apply() } + 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") + // if key is provided, use it useInMemoryPgpKeys(signingId, signingKey, signingPassphrase) } // else use file signing sign(publications) } - repositories { - maven { - name = "sonatype" - url = uri(sonatypeRepo) - credentials { - username = sonatypeUser - password = sonatypePassword - } + repositories.maven { + name = "sonatype" + url = uri(sonatypeRepo) + + credentials { + username = sonatypeUser + password = sonatypePassword } } } } } } - -//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 -- 2.34.1 From dd3d95dba4f027ef98fdf0f0f3b87b997dedc234 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 12 Sep 2021 11:10:50 +0300 Subject: [PATCH 06/16] version update --- build.gradle.kts | 4 +++- .../ru/mipt/npm/gradle/KScienceVersions.kt | 20 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5c1a564..ccbf344 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "ru.mipt.npm" -version = "0.10.2" +version = "0.10.3" description = "Build tools for DataForge and kscience projects" @@ -20,6 +20,8 @@ repositories { maven("https://repo.kotlin.link") } +val kotlinVersion = "1.5.30" + java.targetCompatibility = JavaVersion.VERSION_11 kotlin.explicitApiWarning() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index 84002fe..e68e515 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -5,16 +5,16 @@ import org.gradle.api.JavaVersion /** * Build constants */ -public object KScienceVersions { - public const val kotlinVersion: String = "1.5.21" - public const val kotlinxNodeVersion: String = "0.0.7" - public const val coroutinesVersion: String = "1.5.1" - public const val serializationVersion: String = "1.2.2" - public const val atomicVersion: String = "0.16.2" - public const val ktorVersion: String = "1.6.1" - public const val htmlVersion: String = "0.7.3" - public const val dateTimeVersion: String = "0.2.1" - public const val jsBom: String = "0.0.1-pre.216-kotlin-1.5.20" +object KScienceVersions { + const val kotlinVersion = "1.5.30" + const val kotlinxNodeVersion = "0.0.7" + const val coroutinesVersion = "1.5.1" + const val serializationVersion = "1.2.2" + const val atomicVersion = "0.16.2" + const val ktorVersion = "1.6.2" + const val htmlVersion = "0.7.3" + const val dateTimeVersion = "0.2.1" + const val jsBom = "0.0.1-pre.216-kotlin-1.5.20" public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 -- 2.34.1 From 6fa4b264a2677d4718dacad8e32ee939a1e1524a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 12 Sep 2021 19:32:35 +0300 Subject: [PATCH 07/16] Fix inner use of version catalog --- build.gradle.kts | 18 ++++++++--- gradle/libs.versions.toml | 11 ++++--- settings.gradle.kts | 1 + .../ru/mipt/npm/gradle/KScienceVersions.kt | 31 +++++++++++-------- .../ru/mipt/npm/gradle/internal/common.kt | 13 ++++---- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 74a1892..94174e6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,6 +37,8 @@ dependencies { implementation(libs.kotlin.serialization) } +//declaring exported plugins + gradlePlugin { plugins { create("common") { @@ -83,6 +85,14 @@ gradlePlugin { } } +//publishing version catalog + +catalog.versionCatalog { + from(files("gradle/libs.versions.toml")) +} + +//publishing the artifact + val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") from(sourceSets.named("main").get().allSource) @@ -94,10 +104,6 @@ val javadocsJar by tasks.creating(Jar::class) { from(tasks.dokkaHtml) } -catalog.versionCatalog { - from(files("gradle/libs.versions.toml")) -} - afterEvaluate { publishing { val vcs = "https://github.com/mipt-npm/gradle-tools" @@ -195,3 +201,7 @@ afterEvaluate { } } } + +tasks.processResources.configure { + from("gradle/libs.versions.toml") +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f1037e9..d5e8579 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ atomicfu = "0.16.2" binary-compatibility-validator = "0.6.0" changelog = "1.2.1" dokka = "1.5.0" -kotlin = "1.5.21" +kotlin = "1.5.30" kotlin-jupyter = "0.10.0-184" kotlinx-benchmark = "0.3.1" kotlinx-cli = "0.3.2" @@ -13,11 +13,12 @@ kotlinx-datetime = "0.2.1" kotlinx-html = "0.7.3" kotlinx-knit = "0.2.3" kotlinx-nodejs = "0.0.7" -kotlinx-serialization = "1.2.2" -ktor = "1.6.2" -tools = "0.10.2" +kotlinx-serialization = "1.3.0-RC" +ktor = "1.6.3" +tools = "0.10.3" xmlutil = "0.82.0" -yamlkt = "0.10.0" +yamlkt = "0.10.2" +jsBom = "0.0.1-pre.243-kotlin-1.5.30" [libraries] atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 1a6e4a3..4de58c3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,3 @@ rootProject.name = "gradle-tools" + enableFeaturePreview("VERSION_CATALOGS") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index 3609587..21d9094 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -1,26 +1,31 @@ package ru.mipt.npm.gradle import org.gradle.api.JavaVersion +import org.gradle.internal.impldep.org.tomlj.Toml /** * Build constants */ -@Deprecated("Use version catalog.") -object KScienceVersions { - const val kotlinVersion = "1.5.30" - const val kotlinxNodeVersion = "0.0.7" - const val coroutinesVersion = "1.5.1" - const val serializationVersion = "1.2.2" - const val atomicVersion = "0.16.2" - const val ktorVersion = "1.6.2" - const val htmlVersion = "0.7.3" - const val dateTimeVersion = "0.2.1" - const val jsBom = "0.0.1-pre.216-kotlin-1.5.20" +public object KScienceVersions { + + private val toml = + Toml.parse(KScienceVersions.javaClass.getResource("/libs.versions.toml")!!.readText()) + + + public val kotlinVersion: String = toml.getString("versions.kotlin")!! + public val kotlinxNodeVersion: String = toml.getString("versions.kotlinx-nodejs")!! + public val coroutinesVersion: String = toml.getString("versions.kotlinx-coroutines")!! + public val serializationVersion: String = toml.getString("versions.kotlinx-serialization")!! + public val atomicVersion: String = toml.getString("versions.atomicfu")!! + public val ktorVersion: String = toml.getString("versions.ktor")!! + public val htmlVersion: String = toml.getString("versions.kotlinx-html")!! + public val dateTimeVersion: String = toml.getString("versions.kotlinx-datetime")!! + public val jsBom: String = toml.getString("versions.jsBom")!! public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 public object Serialization { - public const val xmlVersion: String = "0.82.0" - public const val yamlKtVersion: String = "0.10.0" + public val xmlVersion: String = toml.getString("versions.xmlutil")!! + public val yamlKtVersion: String = toml.getString("versions.yamlkt")!! } } 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 f4d8096..2d7fd7d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -15,12 +15,13 @@ internal fun LanguageSettingsBuilder.applySettings() { languageVersion = "1.5" apiVersion = "1.5" progressiveMode = true - useExperimentalAnnotation("kotlin.Experimental") - useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") - useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") - useExperimentalAnnotation("kotlin.time.ExperimentalTime") - useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") - useExperimentalAnnotation("kotlin.js.ExperimentalJsExport") + + optIn("kotlin.Experimental") + optIn("kotlin.ExperimentalUnsignedTypes") + optIn("kotlin.ExperimentalStdlibApi") + optIn("kotlin.time.ExperimentalTime") + optIn("kotlin.contracts.ExperimentalContracts") + optIn("kotlin.js.ExperimentalJsExport") } internal fun RepositoryHandler.applyRepos() { -- 2.34.1 From 878405ac6a643186d576949a477ab3140df9eb13 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 12 Sep 2021 22:06:08 +0300 Subject: [PATCH 08/16] Replace `useJupyter` with `jupyterLibrary` --- gradle/libs.versions.toml | 10 +++++----- .../ru/mipt/npm/gradle/KScienceExtension.kt | 13 +++++++++++- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 20 +++++++++---------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d5e8579..1fae6ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,14 @@ [versions] atomicfu = "0.16.2" -binary-compatibility-validator = "0.6.0" -changelog = "1.2.1" +binary-compatibility-validator = "0.7.1" +changelog = "1.3.0" dokka = "1.5.0" kotlin = "1.5.30" -kotlin-jupyter = "0.10.0-184" +kotlin-jupyter = "0.10.0-227" kotlinx-benchmark = "0.3.1" kotlinx-cli = "0.3.2" kotlinx-collections-immutable = "0.3.4" -kotlinx-coroutines = "1.5.1" +kotlinx-coroutines = "1.5.2" kotlinx-datetime = "0.2.1" kotlinx-html = "0.7.3" kotlinx-knit = "0.2.3" @@ -16,7 +16,7 @@ kotlinx-nodejs = "0.0.7" kotlinx-serialization = "1.3.0-RC" ktor = "1.6.3" tools = "0.10.3" -xmlutil = "0.82.0" +xmlutil = "0.83.0" yamlkt = "0.10.2" jsBom = "0.0.1-pre.243-kotlin-1.5.30" diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index 2b71104..6c07f48 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -4,13 +4,13 @@ import kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin import org.gradle.api.Project import org.gradle.api.plugins.ApplicationPlugin import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask import ru.mipt.npm.gradle.internal.defaultPlatform import ru.mipt.npm.gradle.internal.useCommonDependency import ru.mipt.npm.gradle.internal.useFx @@ -135,10 +135,21 @@ public class KScienceExtension(public val project: Project) { /** * Apply jupyter plugin */ + @Deprecated("Use jupyterLibrary") public fun useJupyter() { project.apply("org.jetbrains.kotlin.jupyter.api") } + /** + * Apply jupyter plugin and add entry point for the jupyter library + */ + public fun jupyterLibrary(pluginClass: String, vararg additionalPluginClasses: String) { + project.apply("org.jetbrains.kotlin.jupyter.api") + project.tasks.named("processJupyterApiResources", JupyterApiResourcesTask::class.java) { + libraryProducers = listOf(pluginClass, *additionalPluginClasses) + } + } + /** * Mark this module as an application module. JVM application should be enabled separately */ diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 93467b7..cafd95a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -65,15 +65,15 @@ public class KSciencePublishingExtension(public val project: Project) { * * @param githubProject the GitHub project. * @param githubOrg the GitHub user or organization. - * @param released whether publish packages in the `release` task to the GitHub repository. + * @param release whether publish packages in the `release` task to the GitHub repository. */ - public fun github(githubProject: String, githubOrg: String = "mipt-npm", released: Boolean = false, published: Boolean = true) { + public fun github(githubProject: String, githubOrg: String = "mipt-npm", release: Boolean = false, publish: Boolean = true) { // Automatically initialize VCS using GitHub if (!isVcsInitialized) git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") - if (published) project.addGithubPublishing(githubOrg, githubProject) - if (released) linkPublicationsToReleaseTask("github") + if (publish) project.addGithubPublishing(githubOrg, githubProject) + if (release) linkPublicationsToReleaseTask("github") } private val releaseTask by lazy { @@ -84,13 +84,13 @@ public class KSciencePublishingExtension(public val project: Project) { * Adds Space Packages Maven repository to publishing. * * @param spaceRepo the repository URL. - * @param released whether publish packages in the `release` task to the Space repository. + * @param release whether publish packages in the `release` task to the Space repository. */ - public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", released: Boolean = false) { + public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", release: Boolean = true) { require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } project.addSpacePublishing(spaceRepo) - if (released) linkPublicationsToReleaseTask("space") + if (release) linkPublicationsToReleaseTask("space") } // // Bintray publishing @@ -102,13 +102,13 @@ public class KSciencePublishingExtension(public val project: Project) { /** * Adds Sonatype Maven repository to publishing. * - * @param released whether publish packages in the `release` task to the Sonatype repository. + * @param release whether publish packages in the `release` task to the Sonatype repository. */ - public fun sonatype(released: Boolean = true) { + public fun sonatype(release: Boolean = true) { require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } project.addSonatypePublishing() - if (released) linkPublicationsToReleaseTask("sonatype") + if (release) linkPublicationsToReleaseTask("sonatype") } } -- 2.34.1 From db9b4dec5055bf42882fc0664d6061d62031d333 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 13 Sep 2021 22:49:41 +0300 Subject: [PATCH 09/16] Fix plugin resolution --- build.gradle.kts | 10 ++++-- .../ru/mipt/npm/gradle/KScienceExtension.kt | 6 ++-- .../ru/mipt/npm/gradle/KScienceJSPlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceJVMPlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceMPPlugin.kt | 6 ++-- .../mipt/npm/gradle/KScienceNativePlugin.kt | 2 +- .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 7 ++--- .../ru/mipt/npm/gradle/KScienceVersions.kt | 31 ++++++++++--------- src/test/kotlin/TestVersions.kt | 10 ++++++ 9 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 src/test/kotlin/TestVersions.kt diff --git a/build.gradle.kts b/build.gradle.kts index 94174e6..747c39e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,8 +21,6 @@ repositories { maven("https://repo.kotlin.link") } -val kotlinVersion = "1.5.30" - java.targetCompatibility = JavaVersion.VERSION_11 kotlin.explicitApiWarning() @@ -35,6 +33,13 @@ dependencies { implementation(libs.dokka.gradle) implementation(libs.kotlin.jupyter.gradle) implementation(libs.kotlin.serialization) + implementation("org.tomlj:tomlj:1.0.0") + + testImplementation(kotlin("test")) +} + +tasks.test { + useJUnitPlatform() } //declaring exported plugins @@ -203,5 +208,6 @@ afterEvaluate { } tasks.processResources.configure { + duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE from("gradle/libs.versions.toml") } \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index 6c07f48..747a768 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -82,7 +82,7 @@ public class KScienceExtension(public val project: Project) { configuration: DependencyConfiguration = DependencyConfiguration.API, block: SerializationTargets.() -> Unit = {}, ): Unit = project.run { - apply("org.jetbrains.kotlin.plugin.serialization") + plugins.apply("org.jetbrains.kotlin.plugin.serialization") val artifactName = if (version.startsWith("0")) { "kotlinx-serialization-runtime" } else { @@ -137,14 +137,14 @@ public class KScienceExtension(public val project: Project) { */ @Deprecated("Use jupyterLibrary") public fun useJupyter() { - project.apply("org.jetbrains.kotlin.jupyter.api") + project.plugins.apply("org.jetbrains.kotlin.jupyter.api") } /** * Apply jupyter plugin and add entry point for the jupyter library */ public fun jupyterLibrary(pluginClass: String, vararg additionalPluginClasses: String) { - project.apply("org.jetbrains.kotlin.jupyter.api") + project.plugins.apply("org.jetbrains.kotlin.jupyter.api") project.tasks.named("processJupyterApiResources", JupyterApiResourcesTask::class.java) { libraryProducers = listOf(pluginClass, *additionalPluginClasses) } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index b44574a..dabc588 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply public open class KScienceJSPlugin : Plugin { override fun apply(project: Project): Unit = project.run { if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) { - apply("org.jetbrains.kotlin.js") + plugins.apply("org.jetbrains.kotlin.js") } else { logger.info("Kotlin JS plugin is already present") } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt index fcfccf9..773d148 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJVMPlugin.kt @@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply public open class KScienceJVMPlugin : Plugin { override fun apply(project: Project): Unit = project.run { if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) - apply("org.jetbrains.kotlin.jvm") + plugins.apply("org.jetbrains.kotlin.jvm") else logger.info("Kotlin JVM plugin is already present") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index c4a39f1..b78ca2c 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -3,11 +3,13 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin public open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { - apply("org.jetbrains.kotlin.multiplatform") + if (!plugins.hasPlugin(KotlinMultiplatformPlugin::class)) { + //apply() for some reason it does not work + plugins.apply("org.jetbrains.kotlin.multiplatform") } else { logger.info("Kotlin MPP plugin is already present") } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 12ce3c8..36c92fa 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -10,7 +10,7 @@ public class KScienceNativePlugin : Plugin { //Apply multiplatform plugin is not applied, apply it if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - apply("org.jetbrains.kotlin.multiplatform") + plugins.apply("org.jetbrains.kotlin.multiplatform") } if (!plugins.hasPlugin(KScienceCommonPlugin::class)) { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index 0e3e0cc..261a337 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -2,10 +2,7 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.findPlugin -import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension /** @@ -16,7 +13,7 @@ public class KScienceNodePlugin : Plugin { //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") - apply("org.jetbrains.kotlin.multiplatform") + plugins.apply("org.jetbrains.kotlin.multiplatform") } if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt index 21d9094..e871acd 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceVersions.kt @@ -1,31 +1,32 @@ package ru.mipt.npm.gradle + import org.gradle.api.JavaVersion -import org.gradle.internal.impldep.org.tomlj.Toml +import org.tomlj.Toml /** * Build constants */ public object KScienceVersions { - private val toml = - Toml.parse(KScienceVersions.javaClass.getResource("/libs.versions.toml")!!.readText()) + private val toml by lazy { + Toml.parse(javaClass.getResource("/libs.versions.toml")!!.readText()) + } - - public val kotlinVersion: String = toml.getString("versions.kotlin")!! - public val kotlinxNodeVersion: String = toml.getString("versions.kotlinx-nodejs")!! - public val coroutinesVersion: String = toml.getString("versions.kotlinx-coroutines")!! - public val serializationVersion: String = toml.getString("versions.kotlinx-serialization")!! - public val atomicVersion: String = toml.getString("versions.atomicfu")!! - public val ktorVersion: String = toml.getString("versions.ktor")!! - public val htmlVersion: String = toml.getString("versions.kotlinx-html")!! - public val dateTimeVersion: String = toml.getString("versions.kotlinx-datetime")!! - public val jsBom: String = toml.getString("versions.jsBom")!! + public val kotlinVersion: String get() = toml.getString("versions.kotlin")!! + public val kotlinxNodeVersion: String get() = toml.getString("versions.kotlinx-nodejs")!! + public val coroutinesVersion: String get() = toml.getString("versions.kotlinx-coroutines")!! + public val serializationVersion: String get() = toml.getString("versions.kotlinx-serialization")!! + public val atomicVersion: String get() = toml.getString("versions.atomicfu")!! + public val ktorVersion: String get() = toml.getString("versions.ktor")!! + public val htmlVersion: String get() = toml.getString("versions.kotlinx-html")!! + public val dateTimeVersion: String get() = toml.getString("versions.kotlinx-datetime")!! + public val jsBom: String get() = toml.getString("versions.jsBom")!! public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11 public object Serialization { - public val xmlVersion: String = toml.getString("versions.xmlutil")!! - public val yamlKtVersion: String = toml.getString("versions.yamlkt")!! + public val xmlVersion: String get() = toml.getString("versions.xmlutil")!! + public val yamlKtVersion: String get() = toml.getString("versions.yamlkt")!! } } diff --git a/src/test/kotlin/TestVersions.kt b/src/test/kotlin/TestVersions.kt new file mode 100644 index 0000000..4d88b50 --- /dev/null +++ b/src/test/kotlin/TestVersions.kt @@ -0,0 +1,10 @@ +package ru.mipt.npm.gradle + +import org.junit.jupiter.api.Test + +class TestPlugins { + @Test + fun testVersions() { + println(KScienceVersions.coroutinesVersion) + } +} \ No newline at end of file -- 2.34.1 From 138ee1cfeaf2e80e07eec0a85288ab328f48b21e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 14 Sep 2021 14:05:52 +0300 Subject: [PATCH 10/16] fix import --- src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index b78ca2c..0b0fa43 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -3,6 +3,7 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.hasPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin public open class KScienceMPPlugin : Plugin { -- 2.34.1 From 8410e7e4980f5f540c809d4ff49afee492ab3b7c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 20 Sep 2021 20:24:44 +0300 Subject: [PATCH 11/16] Fix optin --- gradle/libs.versions.toml | 2 +- src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1fae6ea..98906d1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,4 +1,5 @@ [versions] +tools = "0.10.4" atomicfu = "0.16.2" binary-compatibility-validator = "0.7.1" changelog = "1.3.0" @@ -15,7 +16,6 @@ kotlinx-knit = "0.2.3" kotlinx-nodejs = "0.0.7" kotlinx-serialization = "1.3.0-RC" ktor = "1.6.3" -tools = "0.10.3" xmlutil = "0.83.0" yamlkt = "0.10.2" jsBom = "0.0.1-pre.243-kotlin-1.5.30" 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 2d7fd7d..3c6d337 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -16,7 +16,7 @@ internal fun LanguageSettingsBuilder.applySettings() { apiVersion = "1.5" progressiveMode = true - optIn("kotlin.Experimental") + optIn("kotlin.RequiresOptIn") optIn("kotlin.ExperimentalUnsignedTypes") optIn("kotlin.ExperimentalStdlibApi") optIn("kotlin.time.ExperimentalTime") -- 2.34.1 From 0415ed30d59654bb1114c2e4d7d4994ff49412e3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 20 Sep 2021 21:49:05 +0300 Subject: [PATCH 12/16] Language version 1.6 --- gradle/libs.versions.toml | 2 +- src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 98906d1..266f8ae 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] tools = "0.10.4" +kotlin = "1.5.31" atomicfu = "0.16.2" binary-compatibility-validator = "0.7.1" changelog = "1.3.0" dokka = "1.5.0" -kotlin = "1.5.30" kotlin-jupyter = "0.10.0-227" kotlinx-benchmark = "0.3.1" kotlinx-cli = "0.3.2" 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 3c6d337..b8c8f13 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -12,8 +12,8 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder internal fun LanguageSettingsBuilder.applySettings() { - languageVersion = "1.5" - apiVersion = "1.5" + languageVersion = "1.6" + apiVersion = "1.6" progressiveMode = true optIn("kotlin.RequiresOptIn") -- 2.34.1 From 680bd9ed3365f4c8742bd71f47965973832f2f03 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 27 Sep 2021 20:18:38 +0300 Subject: [PATCH 13/16] Fix language settings --- gradle/libs.versions.toml | 6 +++--- .../ru/mipt/npm/gradle/KScienceCommonPlugin.kt | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 266f8ae..5ff2753 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] tools = "0.10.4" -kotlin = "1.5.31" +kotlin = "1.6.0-M1" atomicfu = "0.16.2" binary-compatibility-validator = "0.7.1" changelog = "1.3.0" @@ -14,11 +14,11 @@ kotlinx-datetime = "0.2.1" kotlinx-html = "0.7.3" kotlinx-knit = "0.2.3" kotlinx-nodejs = "0.0.7" -kotlinx-serialization = "1.3.0-RC" +kotlinx-serialization = "1.3.0" ktor = "1.6.3" xmlutil = "0.83.0" yamlkt = "0.10.2" -jsBom = "0.0.1-pre.243-kotlin-1.5.30" +jsBom = "0.0.1-pre.248-kotlin-1.5.31" [libraries] atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index 70b06c4..1ee4e43 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -28,12 +28,11 @@ public open class KScienceCommonPlugin : Plugin { configure { explicitApiWarning() - sourceSets["main"].apply { + sourceSets.all { languageSettings.applySettings() } sourceSets["test"].apply { - languageSettings.applySettings() dependencies { implementation(kotlin("test-junit5")) implementation("org.junit.jupiter:junit-jupiter:5.6.1") @@ -69,15 +68,17 @@ public open class KScienceCommonPlugin : Plugin { } } - sourceSets["main"].apply { + sourceSets.all { languageSettings.applySettings() + } + + sourceSets["main"].apply { dependencies { api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) } } sourceSets["test"].apply { - languageSettings.applySettings() dependencies { implementation(kotlin("test-js")) } @@ -138,12 +139,8 @@ public open class KScienceCommonPlugin : Plugin { } } - afterEvaluate { - targets.all { - sourceSets.all { - languageSettings.applySettings() - } - } + sourceSets.all { + languageSettings.applySettings() } (tasks.findByName("jsProcessResources") as? Copy)?.apply { -- 2.34.1 From 931d69ec1d5fe63fcfbda2a2d03d5d4c50837c74 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 28 Sep 2021 12:12:03 +0300 Subject: [PATCH 14/16] 0.10.4 --- CHANGELOG.md | 3 +++ build.gradle.kts | 12 ++---------- .../ru/mipt/npm/gradle/KScienceProjectPlugin.kt | 8 ++++---- .../ru/mipt/npm/gradle/internal/publishing.kt | 13 ++++++------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 426e500..33e37e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- Kotlin 1.6 ### Deprecated ### Removed ### Fixed +- Some issues with opt-ins ### Security ## [0.10.2] @@ -22,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Experimental automatic JS project bundling in MPP ### Changed +- Remove vcs requirement for Space publication ### Deprecated diff --git a/build.gradle.kts b/build.gradle.kts index 747c39e..44b20d5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,6 +34,8 @@ dependencies { implementation(libs.kotlin.jupyter.gradle) implementation(libs.kotlin.serialization) implementation("org.tomlj:tomlj:1.0.0") +// // nexus publishing plugin +// implementation("io.github.gradle-nexus:publish-plugin:1.1.0") testImplementation(kotlin("test")) } @@ -189,16 +191,6 @@ afterEvaluate { apply() } - repositories.maven { - name = "sonatype" - url = uri(sonatypeRepo) - - credentials { - username = sonatypeUser - password = sonatypePassword - } - } - signing { //useGpgCmd() sign(publications) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index cafd95a..a6224f7 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -32,7 +32,7 @@ public class KSciencePublishingExtension(public val project: Project) { } /** - * Configures Git repository for the publication. + * Configures Git repository (sources) for the publication. * * @param vcsUrl URL of the repository's web interface. * @param connectionUrl URL of the Git repository. @@ -69,8 +69,9 @@ public class KSciencePublishingExtension(public val project: Project) { */ public fun github(githubProject: String, githubOrg: String = "mipt-npm", release: Boolean = false, publish: Boolean = true) { // Automatically initialize VCS using GitHub - if (!isVcsInitialized) + if (!isVcsInitialized) { git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") + } if (publish) project.addGithubPublishing(githubOrg, githubProject) if (release) linkPublicationsToReleaseTask("github") @@ -87,7 +88,6 @@ public class KSciencePublishingExtension(public val project: Project) { * @param release whether publish packages in the `release` task to the Space repository. */ public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", release: Boolean = true) { - require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } project.addSpacePublishing(spaceRepo) if (release) linkPublicationsToReleaseTask("space") @@ -105,7 +105,7 @@ public class KSciencePublishingExtension(public val project: Project) { * @param release whether publish packages in the `release` task to the Sonatype repository. */ public fun sonatype(release: Boolean = true) { - require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" } + require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" } project.addSonatypePublishing() if (release) linkPublicationsToReleaseTask("sonatype") 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 7185bec..43c7d67 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -25,7 +25,7 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit plugins.withId("org.jetbrains.kotlin.js") { val kotlin: KotlinJsProjectExtension = extensions.findByType()!! - val sourcesJar by tasks.creating(Jar::class) { + val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") kotlin.sourceSets.all { @@ -155,7 +155,7 @@ internal fun Project.addGithubPublishing( internal fun Project.addSpacePublishing(spaceRepo: String) { if (requestPropertyOrNull("publishing.enabled") != "true") { - logger.info("Skipping github publishing because publishing is disabled") + logger.info("Skipping space publishing because publishing is disabled") return } @@ -188,7 +188,7 @@ internal fun Project.addSpacePublishing(spaceRepo: String) { internal fun Project.addSonatypePublishing() { if (requestPropertyOrNull("publishing.enabled") != "true") { - logger.info("Skipping github publishing because publishing is disabled") + logger.info("Skipping sonatype publishing because publishing is disabled") return } @@ -204,18 +204,16 @@ 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 = "https://oss.sonatype.org/service/local/staging/deploy/maven2" - - if (!plugins.hasPlugin("signing") ) { + if (!plugins.hasPlugin("signing")) { apply() } extensions.configure("signing") { + val signingId: String? = requestPropertyOrNull("publishing.signing.id") if (!signingId.isNullOrBlank()) { val signingKey: String = requestProperty("publishing.signing.key") val signingPassphrase: String = requestProperty("publishing.signing.passPhrase") @@ -227,6 +225,7 @@ internal fun Project.addSonatypePublishing() { } repositories.maven { + val sonatypeRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2" name = "sonatype" url = uri(sonatypeRepo) -- 2.34.1 From 1c37a165c25e208510ee46c29586f6a324adafa2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 28 Sep 2021 12:12:28 +0300 Subject: [PATCH 15/16] patch CHANGELOG.md --- CHANGELOG.md | 62 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33e37e1..f4ee22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.10.4] +### Added + ### Changed - Kotlin 1.6 + ### Deprecated ### Removed @@ -18,107 +32,96 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Some issues with opt-ins + ### Security + ## [0.10.2] ### Added - Experimental automatic JS project bundling in MPP + ### Changed - Remove vcs requirement for Space publication -### Deprecated - -### Removed ### Fixed -Release task (#19) -### Security - ## [0.10.0] ### Added - Lazy readme properties - BOM for kotlin-wrappers on JS - Jupyter loader + ### Changed - API validation disabled for dev versions - Kotlin plugins are propagated downstream -### Deprecated ### Removed - bson support -### Fixed - -### Security - ## [0.9.5] ### Added - Disable API validation for snapshots - `-Xjvm-default=all` on JVM + ### Changed - `publication.platform` changed to `publishing.platform` - Dokka version to `1.4.30` - `useDateTime` in extension - Kotlin 1.5 -### Deprecated ### Removed - Publish plugin. Use MavenPublish instead + ### Fixed - Removed unnecessary `afterEvaluate` for compatibility with gradle 7.0 -### 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` + ### 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 - Per-platform release publishing + ### Changed - Kotlin to 1.4.30 stable. - Added intermediate jsCommon main/test sourcesSet for node plugin. @@ -126,19 +129,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Common plugin id changed to `common` - Plugins group changed to `ru.mipt.npm` with `gradle` prefix -### Deprecated ### Removed - kaml + ### Fixed - Fix publishing load order for sonatype - Fix root project readme -### Security - ## [0.7.4] - ### Added - Changelog plugin automatically applied to `project`. - Feature matrix and Readme generation task for a `project` plugin. @@ -147,6 +147,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved all logic to a common plugin, leaving only proxies for platform plugins - Suppress API validation for modules with maturity below DEVELOPMENT + ### Changed - Remove node plugin. Node binaries should be turned on manually. - Use default webpack distribution path. @@ -157,29 +158,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved internals to internals - Kotlin 1.4.30-RC + ### Deprecated - Support of `kaml` and `snake-yaml` in favor of `yamlKt` - Publish plugin + ### Removed - `useDokka` method. Documentation jar should be added manually if needed. - -### Fixed - -### Security ## [0.6.0] - ### Added - Migrate to kotlin 1.4.0 - Separate Native (current platform) and nodeJs plugins. - Add `application()` toggle in plugin configuration to produce binaries on JS and applicaion plugin on jvm. - Add `publish` to expose publishing configuration. + ### Changed -Publishing in bintray now is automatic. ## [0.5.2] - ### Added - Copy resources for jvm modules and jvm source sets in mpp. \ No newline at end of file -- 2.34.1 From 54274f0c0ddeda385c8795ede1575e483ddbbf8f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 28 Sep 2021 12:15:13 +0300 Subject: [PATCH 16/16] Return sonatype publication for the plugin --- build.gradle.kts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 44b20d5..a9b22ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -187,6 +187,16 @@ afterEvaluate { "https://oss.sonatype.org/service/local/staging/deploy/maven2" } + repositories.maven { + name = "sonatype" + url = uri(sonatypeRepo) + + credentials { + username = sonatypeUser + password = sonatypePassword + } + } + if (plugins.findPlugin("signing") == null) { apply() } -- 2.34.1