diff --git a/.gitignore b/.gitignore index 552551ae3..e84ee6450 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ /.idea/* !/.idea/copyright .gradle +.kotlin *.iml target build -/local.properties +local.properties benchmarks.jar diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index b3ff81470..0493fec85 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -1,34 +1,31 @@ -/* - * Copyright 2019-2023 JetBrains s.r.o. and contributors. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { - id("kotlin") - id("me.champeau.jmh") + with(libs.plugins) { + alias(kotlin.jvm) + alias(jmh) + } } - -val mainJavaToolchainVersion by ext(project.property("java.mainToolchainVersion")) -val modularJavaToolchainVersion by ext(project.property("java.modularToolchainVersion")) - sourceSets { dependencies { implementation(project(":kotlinx-datetime")) - implementation("org.openjdk.jmh:jmh-core:1.35") + implementation(libs.jmh) } } -// Publish benchmarks to the root for the easier 'java -jar benchmarks.jar` +// publish benchmarks to the repository root for easier `java -jar benchmarks.jar` tasks.named("jmhJar") { - val nullString: String? = null - archiveBaseName.set("benchmarks") - archiveClassifier.set(nullString) - archiveVersion.set(nullString) - archiveVersion.convention(nullString) - destinationDirectory.set(file("$rootDir")) + archiveBaseName = "benchmarks" + archiveClassifier = null + archiveVersion.convention(null as String?) + archiveVersion = null + destinationDirectory = file("$rootDir") } -repositories { - mavenCentral() +// compile all Kotlin code from the module during full-repository builds +tasks.named("assemble") { + tasks.withType>().forEach { compileKotlinTask -> + dependsOn(compileKotlinTask) + } } diff --git a/build.gradle.kts b/build.gradle.kts index 0c16b804b..b451c7f53 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,22 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile + plugins { - id("kotlinx.team.infra") version "0.4.0-dev-81" - kotlin("multiplatform") apply false - id("org.jetbrains.kotlinx.kover") version "0.8.0-Beta2" + with(libs.plugins) { + alias(kotlinx.infra) + alias(kover) + + alias(kotlin.multiplatform) apply false + } } +fun javaLanguageVersionProperty(propertyName: String) = JavaLanguageVersion.of(property(propertyName) as String) +val mainJavaToolchainVersion by extra(javaLanguageVersionProperty("java.mainToolchainVersion")) +val modularJavaToolchainVersion by extra(javaLanguageVersionProperty("java.modularToolchainVersion")) + infra { - teamcity { - } publishing { include(":kotlinx-datetime") libraryRepoUrl = "https://github.com/Kotlin/kotlinx-datetime" @@ -16,37 +26,11 @@ infra { } } -val mainJavaToolchainVersion by ext(project.property("java.mainToolchainVersion")) -val modularJavaToolchainVersion by ext(project.property("java.modularToolchainVersion")) - -allprojects { - repositories { - addTrainRepositories(project) - mavenCentral() - } - tasks.withType().configureEach { - // outputs the compiler version to logs so we can check whether the train configuration applied - kotlinOptions.freeCompilerArgs += "-version" - } - tasks.withType().configureEach { - compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } - } - tasks.withType().configureEach { - compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } - } -} - -// Disable NPM to NodeJS nightly compatibility check. -// Drop this when NodeJs version that supports latest Wasm become stable -tasks.withType().configureEach { - args.add("--ignore-engines") -} - kover { reports { verify { rule { - // requirement for a minimum lines coverage of 85% + // requirement for a minimum line coverage of 85% minBound(85) } } @@ -57,3 +41,41 @@ dependencies { kover(project(":kotlinx-datetime")) kover(project(":kotlinx-datetime-serialization")) } + +// !! infrastructure for builds as a Kotlin user project +// (although some of these settings are just enabled by default because they're not very invasive anyway) +subprojects { + tasks.withType>().configureEach { + compilerOptions { + // output kotlin.git-searchable names of reported diagnostics + freeCompilerArgs.add("-Xrender-internal-diagnostic-names") + // output reported warnings even in the presence of reported errors + freeCompilerArgs.add("-Xreport-all-warnings") + + with(providers) { + gradleProperty("kotlin_language_version").orNull?.let { optionalOverridingKotlinLanguageVersion -> + languageVersion = KotlinVersion.fromVersion(optionalOverridingKotlinLanguageVersion) + logger.info( + "[ktDT-as-KUP] Overrode the Kotlin language version with $optionalOverridingKotlinLanguageVersion for '$path'" + ) + } + gradleProperty("kotlin_api_version").orNull?.let { optionalOverridingKotlinApiVersion -> + apiVersion = KotlinVersion.fromVersion(optionalOverridingKotlinApiVersion) + logger.info( + "[ktDT-as-KUP] Overrode the Kotlin API version with $optionalOverridingKotlinApiVersion for '$path'" + ) + } + } + } + } + tasks.withType().configureEach { + compilerOptions { + freeCompilerArgs.add("-Xpartial-linkage-loglevel=error") + } + } + tasks.withType().configureEach { + compilerOptions { + freeCompilerArgs.add("-Xpartial-linkage-loglevel=error") + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 5de237f77..000000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import java.util.* - -plugins { - `kotlin-dsl` -} - -val props = Properties().apply { - file("../gradle.properties").inputStream().use { load(it) } -} - -// copy-pasted from `CommunityProjectsBuild`, see the explanation there -fun RepositoryHandler.addTrainRepositories(project: Project) { - if (project.rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) { - mavenLocal() - } - (project.rootProject.properties["kotlin_repo_url"] as? String)?.let(::maven) -} - -// copy-pasted from `CommunityProjectsBuild`, but uses `props` to obtain the non-snapshot version, because -// we don't have access to the properties defined in `gradle.properties` of the encompassing project -val Project.kotlinVersion: String - get() = if (rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) { - rootProject.properties["kotlin_snapshot_version"] as? String ?: error("kotlin_snapshot_version must be specified") - } else { - props.getProperty("defaultKotlinVersion") - } - -repositories { - mavenCentral() - gradlePluginPortal() - addTrainRepositories(project) -} - -dependencies { - fun gradlePlugin(id: String, version: String): String = "$id:$id.gradle.plugin:$version" - implementation(gradlePlugin("org.jetbrains.kotlin.multiplatform", kotlinVersion)) - implementation(gradlePlugin("org.jetbrains.kotlin.plugin.serialization", kotlinVersion)) -} diff --git a/buildSrc/src/main/kotlin/CommunityProjectsBuild.kt b/buildSrc/src/main/kotlin/CommunityProjectsBuild.kt deleted file mode 100644 index e8ae077ab..000000000 --- a/buildSrc/src/main/kotlin/CommunityProjectsBuild.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ -@file:JvmName("CommunityProjectsBuild") - -import org.gradle.api.* -import org.gradle.api.artifacts.dsl.* -import org.gradle.api.artifacts.repositories.* -import org.gradle.kotlin.dsl.* -import java.util.logging.* - -private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger") - -/** - * Functions in this file are responsible for configuring kotlinx-datetime build against a custom dev version - * of Kotlin compiler. - * Such configuration is used in a composite community build of Kotlin in order to check whether not-yet-released changes - * are compatible with our libraries (aka "integration testing that substitues lack of unit testing"). - * - * Three parameters are used to configure the build: - * 1. `build_snapshot_train` - if true, the build is run against a snapshot train of Kotlin compiler - * 2. `kotlin_snapshot_version` - if specified, the build uses a custom Kotlin compiler version - * 3. `kotlin_repo_url` - if specified, the build uses a custom Kotlin compiler repository - * - * If `build_snapshot_train` is true, `kotlin_snapshot_version` must be present. - */ - -/** - * Adds all the repositories that are needed for the Kotlin aggregate build. - */ -fun RepositoryHandler.addTrainRepositories(project: Project) { - if (project.rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) { - mavenLocal() - } - // A kotlin-dev space repository with dev versions of Kotlin. - val devRepoUrl = project.rootProject.properties["kotlin_repo_url"] as? String ?: return - LOGGER.info("""Configured Kotlin Compiler repository url: '$devRepoUrl' for project ${project.name}""") - maven(devRepoUrl) -} - -/** - * The version of Kotlin compiler to use in the Kotlin aggregate build. - */ -// unused, but may be useful in the future -val Project.kotlinVersion: String - get() = if (rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) { - rootProject.properties["kotlin_snapshot_version"] as? String ?: error("kotlin_snapshot_version must be specified") - } else { - rootProject.properties["defaultKotlinVersion"] as String - } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 257d9eed0..5399a17b6 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,50 +1,65 @@ import kotlinx.team.infra.mavenPublicationsPom -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.net.URL -import javax.xml.parsers.DocumentBuilderFactory -import java.io.ByteArrayOutputStream -import java.io.PrintWriter import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JsModuleKind +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.konan.target.Family +import java.io.ByteArrayOutputStream +import java.io.PrintWriter +import java.net.URL +import javax.xml.parsers.DocumentBuilderFactory plugins { - kotlin("multiplatform") - kotlin("plugin.serialization") - id("org.jetbrains.dokka") + with(libs.plugins) { + alias(kotlin.multiplatform) + alias(kotlin.plugin.serialization) + alias(kover) + alias(dokka) + } `maven-publish` - id("org.jetbrains.kotlinx.kover") } -mavenPublicationsPom { - description.set("Kotlin Datetime Library") -} +val mainJavaToolchainVersion: JavaLanguageVersion by project +val modularJavaToolchainVersion: JavaLanguageVersion by project -base { - archivesBaseName = "kotlinx-datetime" // doesn't work +mavenPublicationsPom { + description = "Kotlin Datetime Library" } -val mainJavaToolchainVersion: String by project -val modularJavaToolchainVersion: String by project -val serializationVersion: String by project - java { - toolchain { languageVersion.set(JavaLanguageVersion.of(mainJavaToolchainVersion)) } + toolchain.languageVersion = mainJavaToolchainVersion } kotlin { + // all-targets configuration + explicitApi() + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + freeCompilerArgs.add("-Xexpect-actual-classes") + freeCompilerArgs.add("-Xdont-warn-on-error-suppression") + } + + // target-specific and compilation-specific configuration + + jvm { + attributes { + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, java.toolchain.languageVersion.get().asInt()) + } + } + + // tiers of K/Native targets are in accordance with infra { common("tzfile") { - // Tiers are in accordance with common("tzdbOnFilesystem") { common("linux") { - // Tier 1 - target("linuxX64") // Tier 2 + target("linuxX64") target("linuxArm64") - // Tier 4 (deprecated, but still in demand) + // Deprecated target("linuxArm32Hfp") } common("darwin") { @@ -73,29 +88,35 @@ kotlin { } } common("androidNative") { + // Tier 3 target("androidNativeArm32") target("androidNativeArm64") target("androidNativeX86") target("androidNativeX64") } } - // Tier 3 common("windows") { + // Tier 3 target("mingwX64") } } - jvm { - attributes { - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8) + targets.withType { + compilations["test"].compileTaskProvider.configure { + compilerOptions.freeCompilerArgs.add("-trw") } - compilations.all { - // Set compilation options for JVM target here + if (konanTarget.family == Family.MINGW) { + compilations["test"].cinterops { + create("modern_api") { + defFile("$projectDir/windows/test_cinterop/modern_api.def") + headers("$projectDir/windows/test_cinterop/modern_api.h") + } + } } - } - js { + @OptIn(ExperimentalWasmDsl::class) + wasmJs { nodejs { testTask { useMocha { @@ -103,21 +124,9 @@ kotlin { } } } - compilations.all { - kotlinOptions { - sourceMap = true - moduleKind = "umd" - metaInfo = true - } - } -// compilations["main"].apply { -// kotlinOptions { -// outputFile = "kotlinx-datetime-tmp.js" -// } -// } } - wasmJs { + js { nodejs { testTask { useMocha { @@ -125,194 +134,158 @@ kotlin { } } } - } - @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions { - freeCompilerArgs.add("-Xexpect-actual-classes") + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + sourceMap = true + moduleKind = JsModuleKind.MODULE_UMD + } } + // configuration of source sets + sourceSets.all { val suffixIndex = name.indexOfLast { it.isUpperCase() } val targetName = name.substring(0, suffixIndex) val suffix = name.substring(suffixIndex).lowercase().takeIf { it != "main" } -// println("SOURCE_SET: $name") kotlin.srcDir("$targetName/${suffix ?: "src"}") resources.srcDir("$targetName/${suffix?.let { it + "Resources" } ?: "resources"}") - languageSettings { - // progressiveMode = true - } } - targets.withType { - compilations["test"].kotlinOptions { - freeCompilerArgs += listOf("-trw") - } - if (konanTarget.family == Family.MINGW) { - compilations["test"].cinterops { - create("modern_api") { - defFile("$projectDir/windows/test_cinterop/modern_api.def") - headers("$projectDir/windows/test_cinterop/modern_api.h") - } - } - } - } sourceSets { - commonMain { + val commonMain by getting { dependencies { - compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion") + compileOnly(libs.kotlinx.serialization.core) } } - - commonTest { + val commonTest by getting { dependencies { - api("org.jetbrains.kotlin:kotlin-test") + api(libs.kotlin.test) } } - val jvmMain by getting { - } + val jvmMain by getting + val jvmTest by getting - val jvmTest by getting { + val nativeMain by getting { + dependencies { + api(libs.kotlinx.serialization.core) + } } + val nativeTest by getting val commonJsMain by creating { - dependsOn(commonMain.get()) + dependsOn(commonMain) dependencies { - api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion") - implementation(npm("@js-joda/core", "3.2.0")) + api(libs.kotlinx.serialization.core) + implementation(npm("@js-joda/core", libs.versions.jsJoda.core.get())) } } - val commonJsTest by creating { - dependsOn(commonTest.get()) + dependsOn(commonTest) dependencies { - implementation(npm("@js-joda/timezone", "2.3.0")) + implementation(npm("@js-joda/timezone", libs.versions.jsJoda.timezone.get())) } } - val jsMain by getting { - dependsOn(commonJsMain) - } - - val jsTest by getting { - dependsOn(commonJsTest) - } - val wasmJsMain by getting { dependsOn(commonJsMain) } - val wasmJsTest by getting { dependsOn(commonJsTest) } - val nativeMain by getting { - dependsOn(commonMain.get()) - dependencies { - api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion") - } - } - - val nativeTest by getting { - } - - val darwinMain by getting { + val jsMain by getting { + dependsOn(commonJsMain) } - - val darwinTest by getting { + val jsTest by getting { + dependsOn(commonJsTest) } } } -tasks { - val jvmTest by existing(Test::class) { - // maxHeapSize = "1024m" +val compileJavaModuleInfo by tasks.registering(JavaCompile::class) { + val moduleName = "kotlinx.datetime" // this module's name + val compileKotlinJvm by tasks.getting(KotlinCompile::class) + val sourceDir = file("jvm/java9/") + val targetDir = compileKotlinJvm.destinationDirectory.map { it.dir("../java9/") } + + // Always compile Kotlin classes first before compiling the module descriptor. + dependsOn(compileKotlinJvm) + + // Add the module-info.java source file to the Kotlin compilation. + // The Kotlin compiler currently won't compile a module descriptor itself, + // but it will parse and check module dependencies. + // (Note that module checking only works on JDK 9+ because built-in JDK base modules are not available in earlier versions.) + val javaVersion = compileKotlinJvm.kotlinJavaToolchain.javaVersion.getOrNull() + if (javaVersion?.isJava9Compatible == true) { + logger.info("module-info.java checking is enabled; $compileKotlinJvm is compiled using Java $javaVersion") + compileKotlinJvm.source(sourceDir) + } else { + logger.info("module-info.java checking is disabled") } - val compileJavaModuleInfo by registering(JavaCompile::class) { - val moduleName = "kotlinx.datetime" // this module's name - val compileKotlinJvm by getting(KotlinCompile::class) - val sourceDir = file("jvm/java9/") - val targetDir = compileKotlinJvm.destinationDirectory.map { it.dir("../java9/") } - - // Use a Java 11 compiler for the module info. - javaCompiler.set(project.javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(modularJavaToolchainVersion)) }) - - // Always compile kotlin classes before the module descriptor. - dependsOn(compileKotlinJvm) - - // Add the module-info source file. - source(sourceDir) - - // Also add the module-info.java source file to the Kotlin compile task. - // The Kotlin compiler will parse and check module dependencies, - // but it currently won't compile to a module-info.class file. - // Note that module checking only works on JDK 9+, - // because the JDK built-in base modules are not available in earlier versions. - val javaVersion = compileKotlinJvm.kotlinJavaToolchain.javaVersion.getOrNull() - if (javaVersion?.isJava9Compatible == true) { - logger.info("Module-info checking is enabled; $compileKotlinJvm is compiled using Java $javaVersion") - compileKotlinJvm.source(sourceDir) - } else { - logger.info("Module-info checking is disabled") - } + // Add the module-info.java source file to this task. + source(sourceDir) - // Set the task outputs and destination dir - outputs.dir(targetDir) - destinationDirectory.set(targetDir) + // Configure output destinations of this task. + outputs.dir(targetDir) + destinationDirectory = targetDir - // Configure JVM compatibility - sourceCompatibility = JavaVersion.VERSION_1_9.toString() - targetCompatibility = JavaVersion.VERSION_1_9.toString() + // Use a Java 11 compiler for the module descriptor compilation. + javaCompiler = project.javaToolchains.compilerFor { languageVersion = modularJavaToolchainVersion } - // Set the Java release version. - options.release.set(9) + // Configure the minimum JVM compatibility options and Java release version that support JPMS. + sourceCompatibility = JavaVersion.VERSION_1_9.toString() + targetCompatibility = JavaVersion.VERSION_1_9.toString() + options.release = 9 - // Ignore warnings about using 'requires transitive' on automatic modules. - // not needed when compiling with recent JDKs, e.g. 17 - options.compilerArgs.add("-Xlint:-requires-transitive-automatic") + // Use the same classpath as during the Kotlin compilation. + classpath = compileKotlinJvm.libraries - // Patch the compileKotlinJvm output classes into the compilation so exporting packages works correctly. - options.compilerArgs.addAll(listOf("--patch-module", "$moduleName=${compileKotlinJvm.destinationDirectory.get()}")) + // Ensure that the classpath is interpreted as a module path when compiling the module descriptor. + modularity.inferModulePath = true - // Use the classpath of the compileKotlinJvm task. - // Also ensure that the module path is used instead of classpath. - classpath = compileKotlinJvm.libraries - modularity.inferModulePath.set(true) - } + // Patch compiled Kotlin classes into the module descriptor compilation so that exporting packages works correctly. + options.compilerArgs.addAll(listOf("--patch-module", "$moduleName=${compileKotlinJvm.destinationDirectory.get()}")) - // Configure the JAR task so that it will include the compiled module-info class file. - val jvmJar by existing(Jar::class) { - manifest { - attributes("Multi-Release" to true) - } - from(compileJavaModuleInfo.map { it.destinationDirectory }) { - into("META-INF/versions/9/") - } - } + // Ignore warnings about using `requires transitive` on automatic modules. + // (Not needed when compiling with recent JDKs, e.g., 17.) + options.compilerArgs.add("-Xlint:-requires-transitive-automatic") +} - // Workaround for https://youtrack.jetbrains.com/issue/KT-58303: - // the `clean` task can't delete the expanded.lock file on Windows as it's still held by Gradle, failing the build - val clean by existing(Delete::class) { - setDelete(fileTree(buildDir) { - exclude("tmp/.cache/expanded/expanded.lock") - }) +// Configure the JAR task so that it includes the compiled module descriptor. +val jvmJar by tasks.existing(Jar::class) { + manifest.attributes("Multi-Release" to true) + from(compileJavaModuleInfo.map { it.destinationDirectory }) { + into("META-INF/versions/9/") } +} - // workaround from KT-61313 - withType().configureEach { - val pubName = name.removePrefix("sign").removeSuffix("Publication") +tasks.withType().configureEach { + val dokkaBasePluginConfiguration = """{ "templatesDir" : "${projectDir.toString().replace('\\', '/')}/dokka-templates" }""" + pluginsMapConfiguration = mapOf("org.jetbrains.dokka.base.DokkaBase" to dokkaBasePluginConfiguration) - // These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets + failOnWarning = true + + dokkaSourceSets.configureEach { + kotlin.sourceSets.commonTest.get().kotlin.srcDirs.forEach { + samples.from(it) + } - // Task ':linkDebugTest' uses this output of task ':signPublication' without declaring an explicit or implicit dependency - findByName("linkDebugTest$pubName")?.let { - mustRunAfter(it) + skipDeprecated = true + // hide enum members and undocumented 'toString's + suppressInheritedMembers = true + // hide the `internal` package, which, on JS, has public members generated by Dukat that would otherwise get mentioned + perPackageOption { + matchingRegex = ".*\\.internal(\\..*)?" + suppress = true } - // Task ':compileTestKotlin' uses this output of task ':signPublication' without declaring an explicit or implicit dependency - findByName("compileTestKotlin$pubName")?.let { - mustRunAfter(it) + + sourceLink { + localDirectory = rootDir + remoteUrl = URL("https://github.com/kotlin/kotlinx-datetime/tree/latest-release") + remoteLineSuffix = "#L" } } } @@ -322,7 +295,7 @@ val downloadWindowsZonesMapping by tasks.registering { val output = "$projectDir/windows/src/internal/WindowsZoneNames.kt" outputs.file(output) doLast { - val initialFileContents = try { File(output).readBytes() } catch(e: Throwable) { ByteArray(0) } + val initialFileContents = try { File(output).readBytes() } catch(_: Throwable) { ByteArray(0) } val documentBuilderFactory = DocumentBuilderFactory.newInstance() // otherwise, parsing fails since it can't find the dtd documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) @@ -374,46 +347,29 @@ val downloadWindowsZonesMapping by tasks.registering { val newFileContents = bos.toByteArray() if (!(initialFileContents contentEquals newFileContents)) { File(output).writeBytes(newFileContents) - throw GradleException("The mappings between Windows and IANA timezone names changed. " + - "The new mappings were written to the filesystem.") + throw GradleException( + "The mappings between Windows and IANA timezone names changed. " + + "The new mappings were written to the filesystem." + ) } } } -tasks.withType().configureEach { - pluginsMapConfiguration.set(mapOf("org.jetbrains.dokka.base.DokkaBase" to """{ "templatesDir" : "${projectDir.toString().replace('\\', '/')}/dokka-templates" }""")) +// workaround from KT-61313 +tasks.withType().configureEach { + val platform = name.removePrefix("sign").removeSuffix("Publication") - failOnWarning.set(true) - dokkaSourceSets.configureEach { - kotlin.sourceSets.commonTest.get().kotlin.srcDirs.forEach { samples.from(it) } - // reportUndocumented.set(true) // much noisy output about `hashCode` and serializer encoders, decoders etc - skipDeprecated.set(true) - // Enum members and undocumented toString() - suppressInheritedMembers.set(true) - // hide the `internal` package, which, on JS, has public members generated by Dukat that would get mentioned - perPackageOption { - matchingRegex.set(".*\\.internal(\\..*)?") - suppress.set(true) - } - sourceLink { - localDirectory.set(rootDir) - remoteUrl.set(URL("https://github.com/kotlin/kotlinx-datetime/tree/latest-release")) - remoteLineSuffix.set("#L") - } - } -} + // these tasks only exist for native targets, + // hence 'findByName' to avoid trying to find them for other targets -// Disable intermediate sourceSet compilation because we do not need js-wasmJs artifact -tasks.configureEach { - if (name == "compileCommonJsMainKotlinMetadata") { - enabled = false + // "Task `:compileTestKotlin` uses [...] output of task `:signPublication` + // without declaring an explicit or implicit dependency [...]" + tasks.findByName("compileTestKotlin$platform")?.let { + mustRunAfter(it) + } + // "Task `:linkDebugTest` uses [...] output of task `:signPublication` + // without declaring an explicit or implicit dependency [...]" + tasks.findByName("linkDebugTest$platform")?.let { + mustRunAfter(it) } -} - -// Drop this configuration when the Node.JS version in KGP will support wasm gc milestone 4 -// check it here: -// https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsRootExtension.kt -with(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.apply(rootProject)) { - nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" - nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" } diff --git a/core/native/src/UtcOffset.kt b/core/native/src/UtcOffset.kt index abe8c64da..33b64c541 100644 --- a/core/native/src/UtcOffset.kt +++ b/core/native/src/UtcOffset.kt @@ -5,11 +5,12 @@ package kotlinx.datetime -import kotlinx.datetime.internal.* import kotlinx.datetime.format.* +import kotlinx.datetime.internal.* import kotlinx.datetime.serializers.UtcOffsetSerializer import kotlinx.serialization.Serializable import kotlin.math.abs +import kotlin.native.concurrent.ThreadLocal @Serializable(with = UtcOffsetSerializer::class) public actual class UtcOffset private constructor(public actual val totalSeconds: Int) { diff --git a/gradle.properties b/gradle.properties index 6495a1e67..f3e431350 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,22 +5,17 @@ group=org.jetbrains.kotlinx version=0.6.0 versionSuffix=SNAPSHOT -defaultKotlinVersion=1.9.21 -dokkaVersion=1.9.20 -serializationVersion=1.6.2 -benchmarksVersion=0.7.2 - java.mainToolchainVersion=8 java.modularToolchainVersion=11 -kotlin.js.compiler=ir -kotlin.native.ignoreIncorrectDependencies=true -kotlin.native.ignoreDisabledTargets=true kotlin.mpp.applyDefaultHierarchyTemplate=false +kotlin.native.ignoreDisabledTargets=true -# Workaround for Bintray treating .sha512 files as artifacts -# https://github.com/gradle/gradle/issues/11412 -systemProp.org.gradle.internal.publish.checksums.insecure=true +# TODO [kotlin.git/0e861e386e4b] remove as deprecated after updating to Kotlin 2.0.20+ +kotlin.native.ignoreIncorrectDependencies=true +# TODO [kotlin.git/1f1a0dce3e2c] remove as deprecated after updating to Kotlin 2.0.20+ +kotlin.wasm.stability.nowarn=true +# TODO [kotlinx-team-infra.git#24] remove when kotlinx.team.infra dependency includes the PR in question # stop using pre-HMPP IDEA import workaround in kotlinx.team.infra useNativeBuildInfraInIdea=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..761c5068e --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,35 @@ +[versions] + +kotlinx-infra = "0.4.0-dev-81" + +kotlin = "2.0.10" + +kover = "0.8.0-Beta2" +dokka = "1.9.20" +jmh-plugin = "0.7.2" + +kotlinx-serialization = "1.6.2" +jmh = "1.35" + +jsJoda-core="3.2.0" # NPM dependency '@js-joda/core' +jsJoda-timezone="2.3.0" # NPM dependency '@js-joda/timezone' + +[plugins] + +kotlinx-infra = { id = "kotlinx.team.infra", version.ref = "kotlinx-infra" } + +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm" } # version is provided by kotlin-multiplatform +kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } + +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } +jmh = { id = "me.champeau.jmh", version.ref = "jmh-plugin" } + +[libraries] + +kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } + +kotlinx-serialization-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core", version.ref = "kotlinx-serialization" } +kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" } +jmh = { group = "org.openjdk.jmh", name = "jmh-core", version.ref = "jmh" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba771..2c3521197 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 19acfb4ef..68e8816d7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=ff7bf6a86f09b9b2c40bb8f48b25fc19cf2b2664fd1d220cd7ab833ec758d0d7 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 79a61d421..f5feea6d6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f1..9d21a2183 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index e8bd523e4..4d394a29d 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -52,14 +52,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - brace-expansion@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" @@ -133,11 +125,6 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== - debug@4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" @@ -217,17 +204,16 @@ glob-parent@~5.1.2: dependencies: is-glob "^4.0.1" -glob@7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" - integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== +glob@8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" inherits "2" - minimatch "^3.0.4" + minimatch "^5.0.1" once "^1.3.0" - path-is-absolute "^1.0.0" has-flag@^4.0.0: version "4.0.0" @@ -320,17 +306,17 @@ minimatch@5.0.1: dependencies: brace-expansion "^2.0.1" -minimatch@^3.0.4: - version "3.1.2" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" - integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== +minimatch@^5.0.1: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== dependencies: - brace-expansion "^1.1.7" + brace-expansion "^2.0.1" -mocha@10.2.0: - version "10.2.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" - integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== +mocha@10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.3.0.tgz#0e185c49e6dccf582035c05fa91084a4ff6e3fe9" + integrity sha512-uF2XJs+7xSLsrmIvn37i/wnc91nw7XjOQB8ccyx5aEgdnohr7n+rEiZP23WkCYHjilR6+EboEnbq/ZQDz4LSbg== dependencies: ansi-colors "4.1.1" browser-stdout "1.3.1" @@ -339,13 +325,12 @@ mocha@10.2.0: diff "5.0.0" escape-string-regexp "4.0.0" find-up "5.0.0" - glob "7.2.0" + glob "8.1.0" he "1.2.0" js-yaml "4.1.0" log-symbols "4.1.0" minimatch "5.0.1" ms "2.1.3" - nanoid "3.3.3" serialize-javascript "6.0.0" strip-json-comments "3.1.1" supports-color "8.1.1" @@ -364,11 +349,6 @@ ms@2.1.3: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -nanoid@3.3.3: - version "3.3.3" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" - integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== - normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" @@ -400,11 +380,6 @@ path-exists@^4.0.0: resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg== - picomatch@^2.0.4, picomatch@^2.2.1: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" @@ -496,10 +471,10 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -typescript@5.0.4: - version "5.0.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" - integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== +typescript@5.4.3: + version "5.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" + integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== workerpool@6.2.1: version "6.2.1" diff --git a/serialization/build.gradle.kts b/serialization/build.gradle.kts index 45f8ee6ba..a64cdc12a 100644 --- a/serialization/build.gradle.kts +++ b/serialization/build.gradle.kts @@ -1,109 +1,133 @@ -import java.util.Locale +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JsModuleKind +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { - id("kotlin-multiplatform") - kotlin("plugin.serialization") - id("org.jetbrains.kotlinx.kover") + with(libs.plugins) { + alias(kotlin.multiplatform) + alias(kotlin.plugin.serialization) + alias(kover) + } } -val mainJavaToolchainVersion: String by project -val serializationVersion: String by project +val mainJavaToolchainVersion: JavaLanguageVersion by project +val modularJavaToolchainVersion: JavaLanguageVersion by project java { - toolchain { languageVersion.set(JavaLanguageVersion.of(mainJavaToolchainVersion)) } + toolchain.languageVersion = mainJavaToolchainVersion } kotlin { + // all-targets configuration + + // [^ none that would be specific to this Gradle module] + + // target-specific and compilation-specific configuration + + jvm { + attributes { + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, java.toolchain.languageVersion.get().asInt()) + } + } + + // tiers of K/Native targets are in accordance with infra { - target("linuxX64") - target("linuxArm64") - target("linuxArm32Hfp") - target("mingwX64") + // Tier 1 target("macosX64") target("macosArm64") - target("iosX64") - target("iosArm64") target("iosSimulatorArm64") + target("iosX64") + // Tier 2 + target("linuxX64") + target("linuxArm64") + target("watchosSimulatorArm64") + target("watchosX64") target("watchosArm32") target("watchosArm64") - target("watchosX64") - target("watchosSimulatorArm64") - target("watchosDeviceArm64") - target("tvosArm64") - target("tvosX64") target("tvosSimulatorArm64") + target("tvosX64") + target("tvosArm64") + target("iosArm64") + // Tier 3 + target("mingwX64") + target("watchosDeviceArm64") + // Deprecated + target("linuxArm32Hfp") } - jvm { - attributes { - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8) + targets.withType { + compilations["test"].compileTaskProvider.configure { + compilerOptions.freeCompilerArgs.add("-trw") } } - js { - nodejs { - } - compilations.all { - kotlinOptions { - sourceMap = true - moduleKind = "umd" - metaInfo = true - } - } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs() } + js { + nodejs() - wasmJs { - nodejs { + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + sourceMap = true + moduleKind = JsModuleKind.MODULE_UMD } } + // configuration of source sets + sourceSets.all { val suffixIndex = name.indexOfLast { it.isUpperCase() } val targetName = name.substring(0, suffixIndex) - val suffix = name.substring(suffixIndex).toLowerCase(Locale.ROOT).takeIf { it != "main" } + val suffix = name.substring(suffixIndex).lowercase().takeIf { it != "main" } kotlin.srcDir("$targetName/${suffix ?: "src"}") resources.srcDir("$targetName/${suffix?.let { it + "Resources" } ?: "resources"}") } - targets.withType { - compilations["test"].kotlinOptions { - freeCompilerArgs += listOf("-trw") - } - } - sourceSets { - commonMain { + val commonMain by getting { dependencies { api(project(":kotlinx-datetime")) } } - - commonTest { + val commonTest by getting { dependencies { - api("org.jetbrains.kotlin:kotlin-test") - api("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion") + api(libs.kotlin.test) + api(libs.kotlinx.serialization.json) } } val jvmMain by getting val jvmTest by getting - val jsMain by getting - val jsTest by getting { + val nativeMain by getting + val nativeTest by getting + + val commonJsMain by creating { + dependsOn(commonMain) + } + val commonJsTest by creating { + dependsOn(commonTest) dependencies { - implementation(npm("@js-joda/timezone", "2.3.0")) + implementation(npm("@js-joda/timezone", libs.versions.jsJoda.timezone.get())) } } - val wasmJsMain by getting + val wasmJsMain by getting { + dependsOn(commonJsMain) + } val wasmJsTest by getting { - dependencies { - implementation(npm("@js-joda/timezone", "2.3.0")) - } + dependsOn(commonJsTest) } - val nativeMain by getting - val nativeTest by getting + val jsMain by getting { + dependsOn(commonJsMain) + } + val jsTest by getting { + dependsOn(commonJsTest) + } } -} \ No newline at end of file +} diff --git a/settings.gradle.kts b/settings.gradle.kts index c5845a6ee..33e25150b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,14 +1,49 @@ pluginManagement { repositories { - maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven") mavenCentral() gradlePluginPortal() + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven") + + // !! infrastructure for builds as a Kotlin user project + val optionalKotlinArtifactsRepo = providers.gradleProperty("kotlin_repo_url").orNull + if (optionalKotlinArtifactsRepo != null) { + maven(url = optionalKotlinArtifactsRepo) + logger.info( + "[ktDT-as-KUP] Registered '$optionalKotlinArtifactsRepo' as a plugin Maven repository" + ) + } + } +} + +gradle.projectsLoaded { + allprojects { + repositories { + mavenCentral() + + // !! infrastructure for builds as a Kotlin user project + val optionalKotlinArtifactsRepo = providers.gradleProperty("kotlin_repo_url").orNull + if (optionalKotlinArtifactsRepo != null) { + maven(url = optionalKotlinArtifactsRepo) + logger.info( + "[ktDT-as-KUP] Registered '$optionalKotlinArtifactsRepo' as a dependency Maven repository for '${path}'" + ) + } + } } - val dokkaVersion: String by settings - val benchmarksVersion: String by settings - plugins { - id("org.jetbrains.dokka") version dokkaVersion - id("me.champeau.jmh") version benchmarksVersion +} + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + // !! infrastructure for builds as a Kotlin user project + val optionalOverridingKotlinVersion = providers.gradleProperty("kotlin_version").orNull + if (optionalOverridingKotlinVersion != null) { + version("kotlin", optionalOverridingKotlinVersion) + logger.info( + "[ktDT-as-KUP] Overrode the Kotlin distribution version with $optionalOverridingKotlinVersion" + ) + } + } } } @@ -16,7 +51,8 @@ rootProject.name = "Kotlin-DateTime-library" include(":core") project(":core").name = "kotlinx-datetime" + include(":serialization") project(":serialization").name = "kotlinx-datetime-serialization" -include(":benchmarks") +include(":benchmarks")