From 7d16d0f5c76df85fb0a5585b2dcada0af8d3559a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 12 Dec 2021 12:23:29 +0300 Subject: [PATCH] pre-0.10.8 --- gradle/libs.versions.toml | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../mipt/npm/gradle/KScienceCommonPlugin.kt | 165 +---------------- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 52 +++--- .../mipt/npm/gradle/commonConfigurations.kt | 166 ++++++++++++++++++ .../ru/mipt/npm/gradle/internal/common.kt | 9 +- .../ru/mipt/npm/gradle/internal/publishing.kt | 8 +- 7 files changed, 212 insertions(+), 198 deletions(-) create mode 100644 src/main/kotlin/ru/mipt/npm/gradle/commonConfigurations.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e689a50..8b9468f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,11 @@ [versions] -tools = "0.10.7" +tools = "0.10.8-kotlin-1.6.0" kotlin = "1.6.0" atomicfu = "0.17.0" binary-compatibility-validator = "0.8.0" changelog = "1.3.1" dokka = "1.6.0" -kotlin-jupyter = "0.11.0-6" +kotlin-jupyter = "0.11.0-39" kotlinx-benchmark = "0.3.1" kotlinx-cli = "0.3.3" kotlinx-collections-immutable = "0.3.4" @@ -15,10 +15,10 @@ kotlinx-html = "0.7.3" kotlinx-knit = "0.3.0" kotlinx-nodejs = "0.0.7" kotlinx-serialization = "1.3.1" -ktor = "1.6.5" +ktor = "1.6.6" xmlutil = "0.83.0" yamlkt = "0.10.2" -jsBom = "0.0.1-pre.265-kotlin-1.5.31" +jsBom = "0.0.1-pre.279-kotlin-1.6.0" junit = "5.8.1" [libraries] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..e750102 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-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index 28b16bc..dbdab6e 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -2,169 +2,10 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project -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 -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import ru.mipt.npm.gradle.internal.applyRepos -import ru.mipt.npm.gradle.internal.applySettings -import ru.mipt.npm.gradle.internal.fromJsDependencies @Suppress("UNUSED_VARIABLE") public open class KScienceCommonPlugin : Plugin { - public companion object { - public val defaultJvmArgs: List = listOf("-Xjvm-default=all", "-Xlambdas=indy") - } - - - override fun apply(project: Project): Unit = project.run { - //Common configuration - registerKScienceExtension() - repositories.applyRepos() - - //Configuration for K-JVM plugin - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - //logger.info("Applying KScience configuration for JVM project") - configure { - explicitApiWarning() - - sourceSets.all { - languageSettings.applySettings() - } - - sourceSets["test"].apply { - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") - } - } - } - tasks.withType { - kotlinOptions { - jvmTarget = KScienceVersions.JVM_TARGET.toString() - freeCompilerArgs = freeCompilerArgs + defaultJvmArgs - } - } - - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - } - - tasks.withType { - useJUnitPlatform() - } - } - - pluginManager.withPlugin("org.jetbrains.kotlin.js") { - //logger.info("Applying KScience configuration for JS project") - configure { - explicitApiWarning() - - js(IR) { - browser { - commonWebpackConfig { - cssSupport.enabled = true - } - } - } - - sourceSets.all { - languageSettings.applySettings() - } - - sourceSets["main"].apply { - dependencies { - api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) - } - } - - sourceSets["test"].apply { - dependencies { - implementation(kotlin("test-js")) - } - } - } - - (tasks.findByName("processResources") as? Copy)?.apply { - fromJsDependencies("runtimeClasspath") - } - - } - - pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - configure { - explicitApiWarning() - - jvm { - compilations.all { - kotlinOptions { - jvmTarget = KScienceVersions.JVM_TARGET.toString() - freeCompilerArgs = freeCompilerArgs + defaultJvmArgs - } - } - } - - js(IR) { - browser { - commonWebpackConfig { - cssSupport.enabled = true - } - } - } - - sourceSets { - val commonMain by getting { - dependencies { - api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) - } - } - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - val jvmMain by getting - val jvmTest by getting { - dependencies { - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") - } - } - val jsMain by getting - val jsTest by getting { - dependencies { - implementation(kotlin("test-js")) - } - } - } - - sourceSets.all { - languageSettings.applySettings() - } - - (tasks.findByName("jsProcessResources") as? Copy)?.apply { - fromJsDependencies("jsRuntimeClasspath") - } - - extensions.findByType()?.apply { - targetCompatibility = KScienceVersions.JVM_TARGET - } - - tasks.withType { - useJUnitPlatform() - } - } - } - - // apply dokka for all projects - if (!plugins.hasPlugin("org.jetbrains.dokka")) { - apply() - } - } + override fun apply(project: Project): Unit = project.configureKScience( + KotlinVersion(1, 6, 0) + ) } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 5b75919..6a6bb53 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -54,10 +54,18 @@ public class KSciencePublishingExtension(public val project: Project) { } } + @Suppress("UNUSED_VARIABLE") private val release by project.tasks.creating { + group = KScienceProjectPlugin.RELEASE_GROUP + description = "Publish development or production release based on version suffix" + } + private fun linkPublicationsToReleaseTask(name: String) = project.afterEvaluate { allTasks() .filter { it.name == "publish${publicationTarget}To${name.capitalize()}Repository" } - .forEach { releaseTask?.dependsOn(it) } + .forEach { + logger.info("Linking $it to release") + release.dependsOn(it) + } } /** @@ -65,40 +73,42 @@ public class KSciencePublishingExtension(public val project: Project) { * * @param githubProject the GitHub project. * @param githubOrg the GitHub user or organization. - * @param release whether publish packages in the `release` task to the GitHub repository. + * @param publish add publish task for github. + * @param addToRelease publish packages in the `release` task to the GitHub repository. */ public fun github( githubProject: String, githubOrg: String = "mipt-npm", - release: Boolean = false, - publish: Boolean = true + addToRelease: Boolean = project.requestPropertyOrNull("publishing.github") == "true", ) { // Automatically initialize VCS using GitHub if (!isVcsInitialized) { git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") } - if (publish) project.addGithubPublishing(githubOrg, githubProject) - if (release) linkPublicationsToReleaseTask("github") - } - - private val releaseTask by lazy { - project.tasks.findByName("release") + if (addToRelease) { + try { + project.addGithubPublishing(githubOrg, githubProject) + linkPublicationsToReleaseTask("github") + } catch (t: Throwable){ + project.logger.error("Failed to set up github publication", t) + } + } } /** * Adds Space Packages Maven repository to publishing. * * @param spaceRepo the repository URL. - * @param release whether publish packages in the `release` task to the Space repository. + * @param addToRelease 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 + addToRelease: Boolean = project.requestPropertyOrNull("publishing.space") != "false", ) { project.addSpacePublishing(spaceRepo) - if (release) linkPublicationsToReleaseTask("space") + if (addToRelease) linkPublicationsToReleaseTask("space") } // // Bintray publishing @@ -110,13 +120,15 @@ public class KSciencePublishingExtension(public val project: Project) { /** * Adds Sonatype Maven repository to publishing. * - * @param release whether publish packages in the `release` task to the Sonatype repository. + * @param addToRelease publish packages in the `release` task to the Sonatype repository. */ - public fun sonatype(release: Boolean = true) { + public fun sonatype( + addToRelease: Boolean = (project.requestPropertyOrNull("publishing.sonatype") != "false"), + ) { require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" } project.addSonatypePublishing() - if (release) linkPublicationsToReleaseTask("sonatype") + if (addToRelease) linkPublicationsToReleaseTask("sonatype") } } @@ -246,14 +258,6 @@ public open class KScienceProjectPlugin : Plugin { dependsOn(generateReadme) } - //val patchChangelog by tasks.getting - - @Suppress("UNUSED_VARIABLE") val release by tasks.creating { - group = RELEASE_GROUP - description = "Publish development or production release based on version suffix" - dependsOn(generateReadme) - } - // Disable API validation for snapshots if (isSnapshot()) { extensions.findByType()?.apply { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/commonConfigurations.kt b/src/main/kotlin/ru/mipt/npm/gradle/commonConfigurations.kt new file mode 100644 index 0000000..de1b304 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/commonConfigurations.kt @@ -0,0 +1,166 @@ +package ru.mipt.npm.gradle + +import org.gradle.api.Project +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 +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import ru.mipt.npm.gradle.internal.applyRepos +import ru.mipt.npm.gradle.internal.applySettings +import ru.mipt.npm.gradle.internal.fromJsDependencies + + +private val defaultJvmArgs: List = listOf("-Xjvm-default=all", "-Xlambdas=indy") + +public fun Project.configureKScience( + kotlinVersion: KotlinVersion +){ + //Common configuration + registerKScienceExtension() + repositories.applyRepos() + + //Configuration for K-JVM plugin + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + //logger.info("Applying KScience configuration for JVM project") + configure { + explicitApiWarning() + + sourceSets.all { + languageSettings.applySettings(kotlinVersion) + } + + sourceSets["test"].apply { + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") + } + } + } + tasks.withType { + kotlinOptions { + jvmTarget = KScienceVersions.JVM_TARGET.toString() + freeCompilerArgs = freeCompilerArgs + defaultJvmArgs + } + } + + extensions.findByType()?.apply { + targetCompatibility = KScienceVersions.JVM_TARGET + } + + tasks.withType { + useJUnitPlatform() + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + //logger.info("Applying KScience configuration for JS project") + configure { + explicitApiWarning() + + js(IR) { + browser { + commonWebpackConfig { + cssSupport.enabled = true + } + } + } + + sourceSets.all { + languageSettings.applySettings(kotlinVersion) + } + + sourceSets["main"].apply { + dependencies { + api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) + } + } + + sourceSets["test"].apply { + dependencies { + implementation(kotlin("test-js")) + } + } + } + + (tasks.findByName("processResources") as? Copy)?.apply { + fromJsDependencies("runtimeClasspath") + } + + } + + pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + configure { + explicitApiWarning() + + jvm { + compilations.all { + kotlinOptions { + jvmTarget = KScienceVersions.JVM_TARGET.toString() + freeCompilerArgs = freeCompilerArgs + defaultJvmArgs + } + } + } + + js(IR) { + browser { + commonWebpackConfig { + cssSupport.enabled = true + } + } + } + + sourceSets { + val commonMain by getting { + dependencies { + api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) + } + } + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + val jvmMain by getting + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit5")) + implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") + } + } + val jsMain by getting + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } + + sourceSets.all { + languageSettings.applySettings(kotlinVersion) + } + + (tasks.findByName("jsProcessResources") as? Copy)?.apply { + fromJsDependencies("jsRuntimeClasspath") + } + + extensions.findByType()?.apply { + targetCompatibility = KScienceVersions.JVM_TARGET + } + + tasks.withType { + useJUnitPlatform() + } + } + } + + // apply dokka for all projects + if (!plugins.hasPlugin("org.jetbrains.dokka")) { + apply() + } +} \ No newline at end of file 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 21f0ef9..673d2a1 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/common.kt @@ -11,9 +11,12 @@ 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() { - languageVersion = "1.6" - apiVersion = "1.6" +internal fun LanguageSettingsBuilder.applySettings( + kotlinVersion: KotlinVersion +) { + val versionString = "${kotlinVersion.major}.${kotlinVersion.minor}" + languageVersion = versionString + apiVersion = versionString progressiveMode = true optIn("kotlin.RequiresOptIn") 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 43c7d67..179b3e3 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/internal/publishing.kt @@ -11,10 +11,10 @@ import org.gradle.plugins.signing.SigningPlugin import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -private fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String +internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String ?: System.getenv(propertyName) -private fun Project.requestProperty(propertyName: String): String = requestPropertyOrNull(propertyName) +internal fun Project.requestProperty(propertyName: String): String = requestPropertyOrNull(propertyName) ?: error("Property $propertyName not defined") @@ -126,8 +126,8 @@ internal fun Project.addGithubPublishing( logger.info("Skipping github publishing because publishing is disabled") return } - if (requestPropertyOrNull("publishing.github") == "false") { - logger.info("Skipping github publishing because `publishing.github == false`") + if (requestPropertyOrNull("publishing.github") != "false") { + logger.info("Skipping github publishing because `publishing.github != true`") return }