Kotlin 1.8.20-Beta

This commit is contained in:
Alexander Nozik 2023-02-11 14:28:45 +03:00
parent 979e819c9a
commit 4bfd042f96
4 changed files with 80 additions and 60 deletions

View File

@ -18,8 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- FX plugins - FX plugins
- Unnecessary library shortcuts (html and datetime) - Unnecessary library shortcuts (html and datetime)
- deploy/release tasks
### Fixed ### Fixed
- issues with test sourcesets
### Security ### Security

View File

@ -1,6 +1,6 @@
[versions] [versions]
tools = "0.14.0-kotlin-1.8.10" tools = "0.14.1-kotlin-1.8.20-Beta"
kotlin = "1.8.10" kotlin = "1.8.20-Beta"
atomicfu = "0.19.0" atomicfu = "0.19.0"
binary-compatibility-validator = "0.12.1" binary-compatibility-validator = "0.12.1"
changelog = "2.0.0" changelog = "2.0.0"
@ -20,6 +20,7 @@ yamlkt = "0.12.0"
jsBom = "1.0.0-pre.491" jsBom = "1.0.0-pre.491"
junit = "5.9.2" junit = "5.9.2"
compose = "1.3.0" compose = "1.3.0"
logback = "1.4.5"
[libraries] [libraries]
atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" }
@ -78,6 +79,8 @@ xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", v
yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" } yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" }
logback-classic = {module = "ch.qos.logback:logback-classic", version.ref = "logback"}
[plugins] [plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" } changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }

View File

@ -15,6 +15,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask
@ -88,6 +89,36 @@ public open class KScienceExtension(public val project: Project) {
SerializationTargets(sourceSet, configuration).block() SerializationTargets(sourceSet, configuration).block()
} }
public fun useKtor(version: String = KScienceVersions.ktorVersion): Unit = with(project) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
sourceSets.findByName("commonMain")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
}
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure<KotlinJvmProjectExtension> {
sourceSets.findByName("main")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
}
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure<KotlinJsProjectExtension> {
sourceSets.findByName("main")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
}
}
}
}
}
/** /**
* Apply jupyter plugin and add entry point for the jupyter library. * Apply jupyter plugin and add entry point for the jupyter library.
* If left empty applies a plugin without declaring library producers * If left empty applies a plugin without declaring library producers
@ -154,7 +185,6 @@ public open class KScienceExtension(public val project: Project) {
} }
} }
public class DefaultSourceSet(public val key: String) public class DefaultSourceSet(public val key: String)
public fun dependencies( public fun dependencies(
@ -182,13 +212,17 @@ public open class KScienceExtension(public val project: Project) {
} }
project.extensions.findByType<KotlinMultiplatformExtension>()?.apply { project.extensions.findByType<KotlinMultiplatformExtension>()?.apply {
js(IR) { targets.withType<KotlinJsTargetDsl> {
binaries.executable() binaries.executable()
} }
targets.withType<KotlinNativeTarget> { targets.withType<KotlinNativeTarget> {
binaries.executable() binaries.executable()
} }
targets.withType<KotlinWasmTargetDsl> {
binaries.executable()
}
} }
} }
@ -203,12 +237,21 @@ public open class KScienceExtension(public val project: Project) {
} }
} }
public operator fun DefaultSourceSet.invoke(dependencyBlock: KotlinDependencyHandler.() -> Unit) {
dependencies(this, dependencyBlock)
}
public val commonMain: DefaultSourceSet get() = DefaultSourceSet("commonMain")
public val commonTest: DefaultSourceSet get() = DefaultSourceSet("commonTest")
public val jvmMain: DefaultSourceSet get() = DefaultSourceSet("jvmMain") public val jvmMain: DefaultSourceSet get() = DefaultSourceSet("jvmMain")
public val jvmTest: DefaultSourceSet get() = DefaultSourceSet("jvmTest") public val jvmTest: DefaultSourceSet get() = DefaultSourceSet("jvmTest")
public val jsMain: DefaultSourceSet get() = DefaultSourceSet("jsMain") public val jsMain: DefaultSourceSet get() = DefaultSourceSet("jsMain")
public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest") public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest")
public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain") public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain")
public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest") public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest")
public val wasmMain: DefaultSourceSet get() = DefaultSourceSet("wasmMain")
public val wasmTest: DefaultSourceSet get() = DefaultSourceSet("wasmTest")
} }
@ -286,7 +329,7 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
block() block()
} }
sourceSets { sourceSets {
getByName("jvmMain") { getByName("jvmTest") {
dependencies { dependencies {
implementation(kotlin("test-junit5")) implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
@ -313,6 +356,13 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
browser() browser()
block() block()
} }
sourceSets {
getByName("jsTest") {
dependencies {
implementation(kotlin("test-js"))
}
}
}
} }
(project.tasks.findByName("jsProcessResources") as? Copy)?.apply { (project.tasks.findByName("jsProcessResources") as? Copy)?.apply {
fromJsDependencies("jsRuntimeClasspath") fromJsDependencies("jsRuntimeClasspath")
@ -320,9 +370,20 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
} }
} }
public fun wasm(block: KotlinWasmTargetDsl.() -> Unit = {}) {
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> {
wasm {
browser()
block()
}
}
}
}
public fun jvmAndJs() { public fun jvmAndJs() {
jvm {} jvm()
js {} js()
} }
/** /**
@ -386,7 +447,7 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.macosArm64 -> macosX64( KotlinNativePreset.macosArm64 -> macosArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )

View File

@ -5,7 +5,6 @@ import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.changelog.ChangelogPluginExtension
@ -18,7 +17,6 @@ import space.kscience.gradle.internal.*
*/ */
public class KSciencePublishingExtension(public val project: Project) { public class KSciencePublishingExtension(public val project: Project) {
private var isVcsInitialized = false private var isVcsInitialized = false
internal val repositoryNames = mutableSetOf<String>()
/** /**
* Configures Git repository (sources) for the publication. * Configures Git repository (sources) for the publication.
@ -55,18 +53,16 @@ public class KSciencePublishingExtension(public val project: Project) {
* *
* @param githubProject the GitHub project. * @param githubProject the GitHub project.
* @param githubOrg the GitHub user or organization. * @param githubOrg the GitHub user or organization.
* @param addToRelease publish packages in the `release` task to the GitHub repository. * @param deploy publish packages in the `deploy` task to the GitHub repository.
*/ */
public fun github( public fun github(
githubOrg: String, githubOrg: String,
githubProject: String, githubProject: String,
addToRelease: Boolean = project.requestPropertyOrNull("publishing.github") == "true", deploy: Boolean = project.requestPropertyOrNull("publishing.github") == "true",
) { ) {
if (deploy) {
if (addToRelease) {
try { try {
project.addGithubPublishing(githubOrg, githubProject) project.addGithubPublishing(githubOrg, githubProject)
repositoryNames += "github"
} catch (t: Throwable) { } catch (t: Throwable) {
project.logger.error("Failed to set up github publication", t) project.logger.error("Failed to set up github publication", t)
} }
@ -77,15 +73,12 @@ public class KSciencePublishingExtension(public val project: Project) {
* Adds Space Packages Maven repository to publishing. * Adds Space Packages Maven repository to publishing.
* *
* @param spaceRepo the repository URL. * @param spaceRepo the repository URL.
* @param addToRelease publish packages in the `release` task to the Space repository. * @param deploy publish packages in the `deploy` task to the Space repository.
*/ */
public fun space( public fun space(
spaceRepo: String, spaceRepo: String,
addToRelease: Boolean = project.requestPropertyOrNull("publishing.space") != "false",
) { ) {
project.addSpacePublishing(spaceRepo) project.addSpacePublishing(spaceRepo)
if (addToRelease) repositoryNames += "space"
} }
/** /**
@ -93,13 +86,9 @@ public class KSciencePublishingExtension(public val project: Project) {
* *
* @param addToRelease 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( public fun sonatype() {
addToRelease: Boolean = (project.requestPropertyOrNull("publishing.sonatype") != "false"),
) {
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
project.addSonatypePublishing() project.addSonatypePublishing()
if (addToRelease) repositoryNames += "sonatype"
} }
} }
@ -227,13 +216,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
dependsOn(generateReadme) dependsOn(generateReadme)
} }
val releaseAll by tasks.creating {
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
dependsOn(generateReadme)
}
tasks.create("version") { tasks.create("version") {
group = "publishing" group = "publishing"
val versionFile = project.buildDir.resolve("project-version.txt") val versionFile = project.buildDir.resolve("project-version.txt")
@ -245,34 +227,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
} }
} }
allprojects {
afterEvaluate {
ksciencePublish.repositoryNames.forEach { repositoryName ->
val repositoryNameCapitalized = repositoryName.capitalize()
val pattern = "publish(?<publication>.*)PublicationTo${repositoryNameCapitalized}Repository"
.toRegex()
tasks.withType<PublishToMavenRepository>().forEach forEachPublication@{
val matchResult = pattern.matchEntire(it.name) ?: return@forEachPublication
val publicationName = matchResult.groups["publication"]!!.value.capitalize()
val releaseTaskName = "release$publicationName"
val targetReleaseTask =
rootProject.tasks.findByName(releaseTaskName) ?: rootProject.tasks.create(releaseTaskName) {
group = RELEASE_GROUP
description =
"Publish platform release artifact for $publicationName to all repositories"
}
releaseAll.dependsOn(targetReleaseTask)
targetReleaseTask.dependsOn(it)
}
}
}
}
// Disable API validation for snapshots // Disable API validation for snapshots
if (isInDevelopment) { if (isInDevelopment) {
extensions.findByType<ApiValidationExtension>()?.apply { extensions.findByType<ApiValidationExtension>()?.apply {
@ -288,6 +242,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
} }
public companion object { public companion object {
public const val RELEASE_GROUP: String = "release" public const val DEPLOY_GROUP: String = "deploy"
} }
} }