diff --git a/benchmark/build.gradle b/benchmark/build.gradle deleted file mode 100644 index 751ad78ce..000000000 --- a/benchmark/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'kotlinx-serialization' -apply plugin: 'idea' -apply plugin: 'com.github.johnrengelman.shadow' -apply plugin: 'me.champeau.jmh' - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 -jmh.jmhVersion = "1.35" - -processJmhResources { - doFirst { - duplicatesStrategy(DuplicatesStrategy.EXCLUDE) - } -} - -jmhJar { - archiveBaseName.set('benchmarks') - archiveVersion.set('') - destinationDirectory = file("$rootDir") -} - -// to include benchmark-module jmh source set compilation during build to verify that it is also compiled succesfully -assemble.dependsOn jmhClasses - -tasks.withType(KotlinCompile).configureEach { - kotlinOptions { - if (rootProject.ext.kotlin_lv_override != null) { - languageVersion = rootProject.ext.kotlin_lv_override - freeCompilerArgs += "-Xsuppress-version-warnings" - } - } -} - -dependencies { - implementation 'org.openjdk.jmh:jmh-core:1.35' - implementation 'com.google.guava:guava:31.1-jre' - implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3' - implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3' - implementation "com.squareup.okio:okio:$okio_version" - implementation project(':kotlinx-serialization-core') - implementation project(':kotlinx-serialization-json') - implementation project(':kotlinx-serialization-json-okio') - implementation project(':kotlinx-serialization-protobuf') -} diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts new file mode 100644 index 000000000..7674ff294 --- /dev/null +++ b/benchmark/build.gradle.kts @@ -0,0 +1,64 @@ +import org.jetbrains.kotlin.gradle.dsl.* +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + java + idea + kotlin("jvm") + alias(libs.plugins.serialization) + alias(libs.plugins.shadow) + alias(libs.plugins.jmh) +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +jmh { + jmhVersion.set("1.35") +} + +tasks.processJmhResources { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + +tasks.jmhJar { + archiveBaseName.set("benchmarks") + archiveVersion.set("") + destinationDirectory.set(file("$rootDir")) +} + +// to include benchmark-module jmh source set compilation during build to verify that it is also compiled succesfully +tasks.assemble { + dependsOn(tasks.jmhClasses) +} + +tasks.withType().configureEach { + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 + } + + kotlinOptions { + if (overriddenLanguageVersion != null) { + languageVersion = overriddenLanguageVersion + freeCompilerArgs += "-Xsuppress-version-warnings" + } + } +} + +dependencies { + implementation(libs.jmhCore) + implementation(libs.guava) + implementation(libs.jackson.databind) + implementation(libs.jackson.module.kotlin) + implementation(libs.okio) + implementation(project(":kotlinx-serialization-core")) + implementation(project(":kotlinx-serialization-json")) + implementation(project(":kotlinx-serialization-json-okio")) + implementation(project(":kotlinx-serialization-protobuf")) +} diff --git a/bom/build.gradle b/bom/build.gradle deleted file mode 100644 index 12e2f6b7e..000000000 --- a/bom/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -plugins { - id 'java-platform' -} - -def name = project.name - -dependencies { - constraints { - rootProject.subprojects.each { - if (it.name == name) return - if (!it.plugins.hasPlugin('maven-publish')) return - evaluationDependsOn(it.path) - it.publishing.publications.all { - if (it.artifactId.endsWith("-kotlinMultiplatform")) return - if (it.artifactId.endsWith("-metadata")) return - // Skip platform artifacts (like *-linuxx64, *-macosx64) - // It leads to inconsistent bom when publishing from different platforms - // (e.g. on linux it will include only linuxx64 artifacts and no macosx64) - // It shouldn't be a problem as usually consumers need to use generic *-native artifact - // Gradle will choose correct variant by using metadata attributes - if (it.artifacts.any { it.extension == 'klib' }) return - api("${it.groupId}:${it.artifactId}:${it.version}") - } - } - } -} - -publishing { - publications { - mavenBom(MavenPublication) { - from components.javaPlatform - } - // Disable metadata publication, no need to - it.each { pub -> - pub.moduleDescriptorGenerator = null - tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all { - onlyIf { false } - } - } - } -} diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts new file mode 100644 index 000000000..7e40b929c --- /dev/null +++ b/bom/build.gradle.kts @@ -0,0 +1,51 @@ +import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication + +plugins { + `java-platform` +} + +val name = project.name + +dependencies { + constraints { + rootProject.subprojects.forEach { + if (it.name == name) return@forEach + if (!it.plugins.hasPlugin("maven-publish")) return@forEach + evaluationDependsOn(it.path) + it.publishing.publications.all { + this as MavenPublication + if (artifactId.endsWith("-kotlinMultiplatform")) return@all + if (artifactId.endsWith("-metadata")) return@all + // Skip platform artifacts (like *-linuxx64, *-macosx64) + // It leads to inconsistent bom when publishing from different platforms + // (e.g. on linux it will include only linuxx64 artifacts and no macosx64) + // It shouldn't be a problem as usually consumers need to use generic *-native artifact + // Gradle will choose correct variant by using metadata attributes + if (artifacts.any { it.extension == "klib" }) return@all + this@constraints.api(mapOf("group" to groupId, "name" to artifactId, "version" to version)) + } + } + } +} + +publishing { + publications { + val mavenBom by creating(MavenPublication::class) { + from(components["javaPlatform"]) + } + // Disable metadata publication + forEach { pub -> + pub as DefaultMavenPublication + pub.unsetModuleDescriptorGenerator() + tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all { + onlyIf { false } + } + } + } +} + +fun DefaultMavenPublication.unsetModuleDescriptorGenerator() { + @Suppress("NULL_FOR_NONNULL_TYPE") + val generator: TaskProvider = null + setModuleDescriptorGenerator(generator) +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 873b20c6a..000000000 --- a/build.gradle +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -buildscript { - /** - * Overrides for Teamcity 'K2 User Projects' + 'Aggregate build / Kotlinx libraries compilation' configuration: - * kotlin_repo_url - local repository with snapshot Kotlin compiler - * kotlin_version - kotlin version to use - * kotlin_language_version - LV to use - */ - ext.snapshotRepoUrl = rootProject.properties["kotlin_repo_url"] - ext.kotlin_lv_override = rootProject.properties["kotlin_language_version"] - if (snapshotRepoUrl != null && snapshotRepoUrl != "") { - ext.kotlin_version = rootProject.properties["kotlin_version"] - repositories { - maven { url snapshotRepoUrl } - } - } else if (project.hasProperty("bootstrap")) { - ext.kotlin_version = property('kotlin.version.snapshot') - ext["kotlin.native.home"] = System.getenv("KONAN_LOCAL_DIST") - } else { - ext.kotlin_version = property('kotlin.version') - } - if (project.hasProperty("library.version")) { - ext.overriden_version = property('library.version') - } - ext.experimentalsEnabled = ["-progressive", - "-opt-in=kotlin.ExperimentalMultiplatform", - "-opt-in=kotlinx.serialization.InternalSerializationApi", - "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false" - ] - - ext.experimentalsInTestEnabled = ["-progressive", - "-opt-in=kotlin.ExperimentalMultiplatform", - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", - "-opt-in=kotlinx.serialization.InternalSerializationApi", - "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false" - ] - ext.koverEnabled = property('kover.enabled') ?: true - - def noTeamcityInteractionFlag = rootProject.hasProperty("no_teamcity_interaction") - def buildSnapshotUPFlag = rootProject.hasProperty("build_snapshot_up") - ext.teamcityInteractionDisabled = noTeamcityInteractionFlag || buildSnapshotUPFlag - - /* - * This property group is used to build kotlinx.serialization against Kotlin compiler snapshot. - * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version. - * DO NOT change the name of these properties without adapting kotlinx.train build chain. - */ - def prop = rootProject.properties['build_snapshot_train'] - ext.build_snapshot_train = prop != null && prop != "" - if (build_snapshot_train) { - ext.kotlin_version = rootProject.properties['kotlin_snapshot_version'] - if (kotlin_version == null) { - throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler") - } - repositories { - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } - } - } - - repositories { - maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' } - // kotlin-dev with space redirector - maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" } - mavenCentral() - gradlePluginPortal() - // For Dokka that depends on kotlinx-html - maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" } - mavenLocal() - } - - configurations.classpath { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - if (details.requested.group == 'org.jetbrains.kotlin') { - details.useVersion kotlin_version - } - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" - classpath "org.jetbrains.kotlinx:kover-gradle-plugin:$kover_version" - classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$validator_version" - classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version" - classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.5.3' // Android API check - - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18' - - // Various benchmarking stuff - classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2" - classpath "me.champeau.jmh:jmh-gradle-plugin:0.6.6" - } -} - -// To make it visible for compiler-version.gradle -ext.compilerVersion = org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION -ext.nativeDebugBuild = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG - -apply plugin: 'binary-compatibility-validator' -apply plugin: 'base' -apply plugin: 'kotlinx-knit' - -apiValidation { - ignoredProjects += ["benchmark", "guide", "kotlinx-serialization"] - klib { - it.enabled = true - } -} - -knit { - siteRoot = "https://kotlinlang.org/api/kotlinx.serialization" - moduleDocs = "build/dokka/htmlMultiModule" -} - -// Build API docs for all modules with dokka before running Knit -knitPrepare.dependsOn "dokka" - -apply plugin: 'org.jetbrains.dokka' -dependencies { - dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version") -} - -allprojects { - group 'org.jetbrains.kotlinx' - - def deployVersion = properties['DeployVersion'] - if (deployVersion != null) version = deployVersion - - if (project.hasProperty("bootstrap")) { - version = version + '-SNAPSHOT' - } - - // the only place where HostManager could be instantiated - project.ext.hostManager = new org.jetbrains.kotlin.konan.target.HostManager() - - if (build_snapshot_train) { - // Snapshot-specific - repositories { - mavenLocal() - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } - } - } - - if (snapshotRepoUrl != null && snapshotRepoUrl != "") { - // Snapshot-specific for K2 CI configurations - repositories { - maven { url snapshotRepoUrl } - } - } - - configurations.all { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - if (details.requested.group == 'org.jetbrains.kotlin') { - details.useVersion kotlin_version - } - } - } - - repositories { - mavenCentral() - maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' } - // kotlin-dev with space redirector - maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" } - // For Dokka that depends on kotlinx-html - maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" } - // For local development - mavenLocal() - - } - - tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile).configureEach { - compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } - } - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile).configureEach { - compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } - } -} - -def unpublishedProjects = ["benchmark", "guide", "kotlinx-serialization-json-tests"] as Set -def excludedFromBomProjects = unpublishedProjects + "kotlinx-serialization-bom" as Set -def uncoveredProjects = ["kotlinx-serialization-bom", "benchmark", "guide", "kotlinx-serialization-json-okio"] as Set - -subprojects { - tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { task -> - if (task.name.contains("Test") || task.name.contains("Jmh")) { - task.kotlinOptions.freeCompilerArgs += experimentalsInTestEnabled - } else { - task.kotlinOptions.freeCompilerArgs += experimentalsEnabled - } - } - - apply from: rootProject.file('gradle/teamcity.gradle') - // Configure publishing for some artifacts - if (!unpublishedProjects.contains(project.name)) { - apply from: rootProject.file('gradle/publishing.gradle') - } -} - -subprojects { - // Can't be applied to BOM - if (excludedFromBomProjects.contains(project.name)) return - - // Animalsniffer setup - // Animalsniffer requires java plugin to be applied, but Kotlin 1.9.20 - // relies on `java-base` for Kotlin Multiplatforms `withJava` implementation - // https://github.com/xvik/gradle-animalsniffer-plugin/issues/84 - // https://youtrack.jetbrains.com/issue/KT-59595 - JavaPluginUtil.applyJavaPlugin(project) - apply plugin: 'ru.vyarus.animalsniffer' - - afterEvaluate { // Can be applied only when the project is evaluated - animalsniffer { - sourceSets = [sourceSets.main] - def annotationValue = "kotlinx.serialization.json.internal.SuppressAnimalSniffer" - switch (name) { - case "kotlinx-serialization-core": - annotationValue = "kotlinx.serialization.internal.SuppressAnimalSniffer" - break - case "kotlinx-serialization-hocon": - annotationValue = "kotlinx.serialization.hocon.internal.SuppressAnimalSniffer" - break - case "kotlinx-serialization-protobuf": - annotationValue = "kotlinx.serialization.protobuf.internal.SuppressAnimalSniffer" - } - annotation = annotationValue - } - dependencies { - signature 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature' - signature 'org.codehaus.mojo.signature:java18:1.0@signature' - } - - // Add dependency on kotlinx-serialization-bom inside other kotlinx-serialization modules themselves, so they have same versions - BomKt.addBomApiDependency(project, ":kotlinx-serialization-bom") - } -} - -// Kover setup -subprojects { - if (uncoveredProjects.contains(project.name)) return - - apply from: rootProject.file("gradle/kover.gradle") -} - -apply from: rootProject.file('gradle/compiler-version.gradle') -apply from: rootProject.file("gradle/dokka.gradle") -apply from: rootProject.file("gradle/benchmark-parsing.gradle") - -tasks.named("dokkaHtmlMultiModule") { - pluginsMapConfiguration.set(["org.jetbrains.dokka.base.DokkaBase": """{ "templatesDir": "${projectDir.toString().replace('\\', '/')}/dokka-templates" }"""]) -} - -tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach { - args.add("--ignore-engines") -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..3857103e3 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,191 @@ +/* + * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import kotlinx.validation.* +import org.jetbrains.dokka.gradle.* + +plugins { + base + alias(libs.plugins.knit) + id("org.jetbrains.kotlinx.binary-compatibility-validator") + id("org.jetbrains.dokka") + id("benchmark-conventions") + + alias(libs.plugins.serialization) apply false +} + +repositories { + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") + // kotlin-dev with space redirector + maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") + // For Dokka that depends on kotlinx-html + maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") + // For local development + mavenLocal() +} + +// == common projects settings setup +allprojects { + // group setup + group = "org.jetbrains.kotlinx" + + // version setup + val deployVersion = properties["DeployVersion"] + if (deployVersion != null) version = deployVersion + if (project.hasProperty("bootstrap")) { + version = "$version-SNAPSHOT" + } + + // repositories setup + if (propertyIsTrue("build_snapshot_train")) { + // Snapshot-specific + repositories { + mavenLocal() + maven("https://oss.sonatype.org/content/repositories/snapshots") + } + } + val snapshotRepoUrl = findProperty("kotlin_repo_url") + if (snapshotRepoUrl != null && snapshotRepoUrl != "") { + // Snapshot-specific for K2 CI configurations + repositories { + maven(snapshotRepoUrl) + } + } + repositories { + mavenCentral() + } +} + +// == BCV setup == +apiValidation { + ignoredProjects.addAll(listOf("benchmark", "guide", "kotlinx-serialization")) + @OptIn(ExperimentalBCVApi::class) + klib { + enabled = true + } +} + +// == Knit setup == + +knit { + siteRoot = "https://kotlinlang.org/api/kotlinx.serialization" + moduleDocs = "build/dokka/htmlMultiModule" +} + +// Build API docs for all modules with dokka before running Knit +tasks.named("knitPrepare") { + dependsOn("dokka") +} + + +// == compiler flags setup == + +tasks.withType().configureEach { + compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } +} +tasks.withType().configureEach { + compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } +} + +subprojects { + tasks.withType>().configureEach { + if (name.contains("Test") || name.contains("Jmh")) { + compilerOptions.freeCompilerArgs.addAll(experimentalsInTestEnabled) + } else { + compilerOptions.freeCompilerArgs.addAll(experimentalsEnabled) + } + } +} + +// == TeamCity setup == +subprojects { + apply(plugin = "teamcity-conventions") +} + +// == publishing setup == +subprojects { + if (name in unpublishedProjects) return@subprojects + apply(plugin = "publishing-conventions") +} + +// == animalsniffer setup == +subprojects { + // Can't be applied to BOM + if (excludedFromBomProjects.contains(project.name)) return@subprojects + apply(plugin = "animalsniffer-conventions") +} + +// == BOM setup == +subprojects { + // Can't be applied to BOM + if (excludedFromBomProjects.contains(project.name)) return@subprojects + apply(plugin = "bom-conventions") +} + +// == Kover setup == +subprojects { + if (uncoveredProjects.contains(project.name)) return@subprojects + apply(plugin = "kover-conventions") +} + +// == Dokka setup == +subprojects { + if (name in documentedSubprojects) { + apply(plugin = "dokka-conventions") + } +} + +// Knit relies on Dokka task and it's pretty convenient +tasks.register("dokka") { + dependsOn("dokkaHtmlMultiModule") +} + +tasks.withType().named("dokkaHtmlMultiModule") { + pluginsMapConfiguration.put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "${projectDir.toString().replace("\\", "/")}/dokka-templates" }""") +} + +dependencies { + dokkaPlugin(libs.dokka.pathsaver) +} + +// == NPM setup == + +tasks.withType().configureEach { + args.add("--ignore-engines") +} + +// == compiler version setup == +gradle.taskGraph.whenReady { + println("Using Kotlin compiler version: ${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}") +} + +// == projects lists and flags == +// getters are required because of variable lazy initialization in Gradle +val unpublishedProjects get() = setOf("benchmark", "guide", "kotlinx-serialization-json-tests") +val excludedFromBomProjects get() = unpublishedProjects + "kotlinx-serialization-bom" +val experimentalsEnabled get() = listOf( + "-progressive", + "-opt-in=kotlin.ExperimentalMultiplatform", + "-opt-in=kotlinx.serialization.InternalSerializationApi", + "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false" +) + +val experimentalsInTestEnabled get() = listOf( + "-progressive", + "-opt-in=kotlin.ExperimentalMultiplatform", + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-opt-in=kotlinx.serialization.InternalSerializationApi", + "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false" +) + +val documentedSubprojects get() = setOf("kotlinx-serialization-core", + "kotlinx-serialization-json", + "kotlinx-serialization-json-okio", + "kotlinx-serialization-cbor", + "kotlinx-serialization-properties", + "kotlinx-serialization-hocon", + "kotlinx-serialization-protobuf") + +val uncoveredProjects get() = setOf("kotlinx-serialization-bom", "benchmark", "guide", "kotlinx-serialization-json-okio") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index c999bcd26..295378bd0 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,43 +2,46 @@ * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -import java.util.* -import java.io.FileInputStream - plugins { `kotlin-dsl` } repositories { - mavenCentral() - mavenLocal() - if (project.hasProperty("kotlin_repo_url")) { - maven(project.properties["kotlin_repo_url"] as String) + /** + * Overrides for Teamcity 'K2 User Projects' + 'Aggregate build / Kotlinx libraries compilation' configuration: + * kotlin_repo_url - local repository with snapshot Kotlin compiler + * kotlin_version - kotlin version to use + * kotlin_language_version - LV to use + */ + val snapshotRepoUrl = findProperty("kotlin_repo_url") as String? + if (snapshotRepoUrl?.isNotEmpty() == true) { + maven(snapshotRepoUrl) } + /* + * This property group is used to build kotlinx.serialization against Kotlin compiler snapshot. + * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version. + * DO NOT change the name of these properties without adapting kotlinx.train build chain. + */ + if ((findProperty("build_snapshot_train") as? String?).equals("true", true)) { + maven("https://oss.sonatype.org/content/repositories/snapshots") + } + // kotlin-dev with space redirector maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") -} -val kotlinVersion = run { - if (project.hasProperty("build_snapshot_train")) { - val ver = project.properties["kotlin_snapshot_version"] as? String - require(!ver.isNullOrBlank()) {"kotlin_snapshot_version must be present if build_snapshot_train is used" } - return@run ver - } - if (project.hasProperty("kotlin_repo_url")) { - val ver = project.properties["kotlin_version"] as? String - require(!ver.isNullOrBlank()) {"kotlin_version must be present if kotlin_repo_url is used" } - return@run ver - } - val targetProp = if (project.hasProperty("bootstrap")) "kotlin.version.snapshot" else "kotlin.version" - FileInputStream(file("../gradle.properties")).use { propFile -> - val ver = project.findProperty("kotlin.version")?.toString() ?: Properties().apply { load(propFile) }[targetProp] - require(ver is String) { "$targetProp must be string in ../gradle.properties, got $ver instead" } - ver - } + maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") + // For Dokka that depends on kotlinx-html + maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") + + mavenCentral() + mavenLocal() } dependencies { - implementation(kotlin("gradle-plugin", kotlinVersion)) + implementation(libs.gradlePlugin.kotlin) + implementation(libs.gradlePlugin.kover) + implementation(libs.gradlePlugin.dokka) + implementation(libs.gradlePlugin.animalsniffer) + implementation(libs.gradlePlugin.binaryCompatibilityValidator) } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..b450fd5e8 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,51 @@ +import java.io.* +import java.util.* + +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + + overriddenKotlinVersion()?.also { overriddenVersion -> + logger.info("Overriding Kotlin version in buildSrc: $overriddenVersion") + version("kotlin", overriddenVersion) + } + } + } +} + +fun overriddenKotlinVersion(): String? { + val kotlinRepoUrl: String? = providers.gradleProperty("kotlin_repo_url").orNull + val repoVersion: String? = providers.gradleProperty("kotlin_version").orNull + val repoVersionFile: String? + + val bootstrap: String? = providers.gradleProperty("bootstrap").orNull + val bootstrapVersion: String? = providers.gradleProperty("kotlin.version.snapshot").orNull + val bootstrapVersionFile: String? + + val buildSnapshotTrain: String? = providers.gradleProperty("build_snapshot_train").orNull + val trainVersion: String? = providers.gradleProperty("kotlin_snapshot_version").orNull + val trainVersionFile: String? + + FileInputStream(file("../gradle.properties")).use { propFile -> + val properties = Properties() + properties.load(propFile) + repoVersionFile = properties["kotlin_version"] as String? + bootstrapVersionFile = properties["kotlin.version.snapshot"] as String? + trainVersionFile = properties["kotlin_snapshot_version"] as String? + } + + if (kotlinRepoUrl?.isNotEmpty() == true) { + return repoVersion ?: repoVersionFile ?: throw IllegalArgumentException("\"kotlin_version\" Gradle property should be defined") + } else if (bootstrap != null) { + return bootstrapVersion ?: bootstrapVersionFile ?: throw IllegalArgumentException("\"kotlin.version.snapshot\" Gradle property should be defined") + } + if (buildSnapshotTrain?.isNotEmpty() == true) { + return trainVersion ?: trainVersionFile ?: throw IllegalArgumentException("\"kotlin_snapshot_version\" should be defined when building with snapshot compiler") + } + return null +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/KotlinVersion.kt b/buildSrc/src/main/kotlin/KotlinVersion.kt deleted file mode 100644 index 5ac051eca..000000000 --- a/buildSrc/src/main/kotlin/KotlinVersion.kt +++ /dev/null @@ -1,14 +0,0 @@ -@file:JvmName("KotlinVersion") - -fun isKotlinVersionAtLeast(kotlinVersion: String, atLeastMajor: Int, atLeastMinor: Int, atLeastPatch: Int): Boolean { - val (major, minor) = kotlinVersion - .split('.') - .take(2) - .map { it.toInt() } - val patch = kotlinVersion.substringAfterLast('.').substringBefore('-').toInt() - return when { - major > atLeastMajor -> true - major < atLeastMajor -> false - else -> (minor == atLeastMinor && patch >= atLeastPatch) || minor > atLeastMinor - } -} diff --git a/buildSrc/src/main/kotlin/Projects.kt b/buildSrc/src/main/kotlin/Projects.kt new file mode 100644 index 000000000..67ff49ca5 --- /dev/null +++ b/buildSrc/src/main/kotlin/Projects.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.gradle.api.* +import org.gradle.api.tasks.* + +val Project.sourceSets: SourceSetContainer + get() = extensions.getByName("sourceSets") as SourceSetContainer + +fun Project.propertyIsTrue(propertyName: String): Boolean { + return (findProperty(propertyName) as? String?).equals("true", true) +} + +val Project.overriddenLanguageVersion : String? + get() = findProperty("kotlin_language_version") as String? + +val Project.teamcityInteractionEnabled : Boolean + get() = !hasProperty("no_teamcity_interaction") && !hasProperty("build_snapshot_up") diff --git a/buildSrc/src/main/kotlin/Publishing.kt b/buildSrc/src/main/kotlin/Publishing.kt deleted file mode 100644 index a855da97b..000000000 --- a/buildSrc/src/main/kotlin/Publishing.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("UnstableApiUsage") - -import org.gradle.api.* -import org.gradle.api.artifacts.dsl.* -import org.gradle.api.provider.* -import org.gradle.api.publish.maven.* -import org.gradle.plugins.signing.* -import java.net.* - -// Pom configuration - -infix fun Property.by(value: T) { - set(value) -} - -fun MavenPom.configureMavenCentralMetadata(project: Project) { - name by project.name - description by "Kotlin multiplatform serialization runtime library" - url by "https://github.com/Kotlin/kotlinx.serialization" - - licenses { - license { - name by "The Apache Software License, Version 2.0" - url by "https://www.apache.org/licenses/LICENSE-2.0.txt" - distribution by "repo" - } - } - - developers { - developer { - id by "JetBrains" - name by "JetBrains Team" - organization by "JetBrains" - organizationUrl by "https://www.jetbrains.com" - } - } - - scm { - url by "https://github.com/Kotlin/kotlinx.serialization" - } -} - -fun mavenRepositoryUri(): URI { - // TODO -SNAPSHOT detection can be made here as well - val repositoryId: String? = System.getenv("libs.repository.id") - return if (repositoryId == null) { - URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - } else { - URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId") - } -} - -fun configureMavenPublication(rh: RepositoryHandler, project: Project) { - rh.maven { - url = mavenRepositoryUri() - credentials { - username = project.getSensitiveProperty("libs.sonatype.user") - password = project.getSensitiveProperty("libs.sonatype.password") - } - } -} - -fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) { - val keyId = project.getSensitiveProperty("libs.sign.key.id") - val signingKey = project.getSensitiveProperty("libs.sign.key.private") - val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase") - if (!signingKey.isNullOrBlank()) { - project.extensions.configure("signing") { - useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) - sign(publication) - } - } -} - -private fun Project.getSensitiveProperty(name: String): String? { - return project.findProperty(name) as? String ?: System.getenv(name) -} diff --git a/buildSrc/src/main/kotlin/animalsniffer-conventions.gradle.kts b/buildSrc/src/main/kotlin/animalsniffer-conventions.gradle.kts new file mode 100644 index 000000000..246dd3aef --- /dev/null +++ b/buildSrc/src/main/kotlin/animalsniffer-conventions.gradle.kts @@ -0,0 +1,66 @@ +import org.gradle.api.* +import org.gradle.api.plugins.* +import org.gradle.api.tasks.* +import org.gradle.api.tasks.bundling.* +import org.gradle.api.tasks.testing.* +import org.gradle.kotlin.dsl.* +import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension + +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +// Animalsniffer setup +// Animalsniffer requires java plugin to be applied, but Kotlin 1.9.20 +// relies on `java-base` for Kotlin Multiplatforms `withJava` implementation +// https://github.com/xvik/gradle-animalsniffer-plugin/issues/84 +// https://youtrack.jetbrains.com/issue/KT-59595 +plugins { + java + id("ru.vyarus.animalsniffer") +} + + +plugins.withId("org.jetbrains.kotlin.multiplatform") { + listOf( + JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, + JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME + ).forEach { outputConfigurationName -> + configurations.findByName(outputConfigurationName)?.isCanBeConsumed = false + } + + disableJavaPluginTasks(extensions.getByName("sourceSets") as SourceSetContainer) +} + +fun Project.disableJavaPluginTasks(javaSourceSet: SourceSetContainer) { + project.tasks.withType(Jar::class.java).named(javaSourceSet.getByName("main").jarTaskName).configure { + dependsOn("jvmTest") + enabled = false + } + + project.tasks.withType(Test::class.java).named(JavaPlugin.TEST_TASK_NAME) { + dependsOn("jvmJar") + enabled = false + } +} + + +afterEvaluate { // Can be applied only when the project is evaluated + extensions.configure { + sourceSets = listOf(this@afterEvaluate.sourceSets["main"]) + + val annotationValue = when(name) { + "kotlinx-serialization-core" -> "kotlinx.serialization.internal.SuppressAnimalSniffer" + "kotlinx-serialization-hocon" -> "kotlinx.serialization.hocon.internal.SuppressAnimalSniffer" + "kotlinx-serialization-protobuf" -> "kotlinx.serialization.protobuf.internal.SuppressAnimalSniffer" + else -> "kotlinx.serialization.json.internal.SuppressAnimalSniffer" + } + + annotation = annotationValue + } + dependencies { + "signature"("net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature") + "signature"("org.codehaus.mojo.signature:java18:1.0@signature") + } + +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts b/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts new file mode 100644 index 000000000..b70b577cf --- /dev/null +++ b/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts @@ -0,0 +1,31 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import groovy.json.JsonSlurper +import java.io.FileNotFoundException + +/** + * Utility for printing benchmark results. + * Results can be obtained with JMH flags + * -rf json -rff serialization-benchmark-results.json + */ +open class PrintBenchmarksTask: DefaultTask() { + private val fileName: String = "serialization-benchmark-results.json" + + @Suppress("UNCHECKED_CAST") + @TaskAction + fun printBenchmarkJsonAsTeamcityStats() { + val jsonFile = project.file(fileName) + if (!jsonFile.exists()) throw TaskExecutionException(this, FileNotFoundException("File $fileName not found")) + val parsedJson = JsonSlurper().parseText(jsonFile.readText()) as Iterable> + + parsedJson.forEach { v -> + val name = (v["benchmark"] as String).substringAfter("kotlinx.benchmarks.") + val score = (v["primaryMetric"] as Map)["score"] + println("##teamcity[buildStatisticValue key='$name' value='$score']") + } + } +} + +tasks.register("printBenchmarksJsonAsTeamcityStats") diff --git a/buildSrc/src/main/kotlin/Bom.kt b/buildSrc/src/main/kotlin/bom-conventions.gradle.kts similarity index 75% rename from buildSrc/src/main/kotlin/Bom.kt rename to buildSrc/src/main/kotlin/bom-conventions.gradle.kts index 7f93ed38a..12df5e395 100644 --- a/buildSrc/src/main/kotlin/Bom.kt +++ b/buildSrc/src/main/kotlin/bom-conventions.gradle.kts @@ -1,12 +1,11 @@ /* - * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -import org.gradle.api.Project import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.* -fun Project.addBomApiDependency(bomProjectPath: String) { +afterEvaluate { val isMultiplatform = plugins.hasPlugin("kotlin-multiplatform") if (isMultiplatform) { @@ -20,3 +19,4 @@ fun Project.addBomApiDependency(bomProjectPath: String) { } } +val bomProjectPath = ":kotlinx-serialization-bom" diff --git a/buildSrc/src/main/kotlin/dokka-conventions.gradle.kts b/buildSrc/src/main/kotlin/dokka-conventions.gradle.kts new file mode 100644 index 000000000..3a783f758 --- /dev/null +++ b/buildSrc/src/main/kotlin/dokka-conventions.gradle.kts @@ -0,0 +1,79 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.jetbrains.dokka.gradle.* +import java.net.URL + +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("org.jetbrains.dokka") +} + +val extens = extensions +dependencies { + dokkaPlugin(provider { extens.getByType().named("libs").findLibrary("dokka.pathsaver").get().get() }) +} + +tasks.withType().named("dokkaHtmlPartial") { + outputDirectory.set(file("build/dokka")) + + + pluginsMapConfiguration.put("org.jetbrains.dokka.base.DokkaBase", """{ "templatesDir": "${rootDir.resolve("dokka-templates").canonicalPath.replace('\\', '/')}" }""") + + dokkaSourceSets { + configureEach { + includes.from(rootDir.resolve("dokka/moduledoc.md").path) + + perPackageOption { + matchingRegex.set("kotlinx\\.serialization(\$|\\.).*") + reportUndocumented.set(true) + skipDeprecated.set(true) + } + + // Internal API + perPackageOption { + matchingRegex.set("kotlinx\\.serialization.internal(\$|\\.).*") + suppress.set(true) + } + + // Internal JSON API + perPackageOption { + matchingRegex.set("kotlinx\\.serialization.json.internal(\$|\\.).*") + suppress.set(true) + reportUndocumented.set(false) + } + + // Workaround for typealias + perPackageOption { + matchingRegex.set("kotlinx\\.serialization.protobuf.internal(\$|\\.).*") + suppress.set(true) + reportUndocumented.set(false) + } + + // Deprecated migrations + perPackageOption { + matchingRegex.set("kotlinx\\.protobuf(\$|\\.).*") + reportUndocumented.set(true) + skipDeprecated.set(true) + } + + // Deprecated migrations + perPackageOption { + matchingRegex.set("org\\.jetbrains\\.kotlinx\\.serialization\\.config(\$|\\.).*") + reportUndocumented.set(false) + skipDeprecated.set(true) + } + + sourceLink { + localDirectory.set(rootDir) + + remoteUrl.set(URL("https://github.com/Kotlin/kotlinx.serialization/tree/master")) + remoteLineSuffix.set("#L") + } + } + } +} \ No newline at end of file diff --git a/gradle/kover.gradle b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts similarity index 53% rename from gradle/kover.gradle rename to buildSrc/src/main/kotlin/kover-conventions.gradle.kts index e0bc71faf..94b77cd54 100644 --- a/gradle/kover.gradle +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -1,11 +1,12 @@ /* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ - -apply plugin: 'org.jetbrains.kotlinx.kover' +plugins { + id("org.jetbrains.kotlinx.kover") +} kover { - if (!rootProject.ext.koverEnabled) { + if (hasProperty("kover.enabled") && property("kover.enabled") != "true") { disable() } @@ -14,7 +15,7 @@ kover { rule("Minimal line coverage rate in percents") { // Core is mainly uncovered because a lot of serializers are tested with JSON - def minPercentage = (project.name.contains("core") || project.name.contains("properties") || project.name.contains("json-okio")) ? 44 : 80 + val minPercentage = if (project.name.contains("core") || project.name.contains("properties") || project.name.contains("json-okio")) 44 else 80 minBound(minPercentage) // valueType is 'COVERED_LINES_PERCENTAGE' by default } diff --git a/buildSrc/src/main/kotlin/native-targets-conventions.gradle.kts b/buildSrc/src/main/kotlin/native-targets-conventions.gradle.kts new file mode 100644 index 000000000..20433b66c --- /dev/null +++ b/buildSrc/src/main/kotlin/native-targets-conventions.gradle.kts @@ -0,0 +1,54 @@ +import org.jetbrains.kotlin.gradle.* + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + kotlin("multiplatform") +} + +kotlin { + @OptIn(ExperimentalKotlinGradlePluginApi::class) + applyDefaultHierarchyTemplate { + + } + + // According to https://kotlinlang.org/docs/native-target-support.html + // Tier 1 + macosX64() + macosArm64() + iosSimulatorArm64() + iosX64() + + // Tier 2 + linuxX64() + linuxArm64() + watchosSimulatorArm64() + watchosX64() + watchosArm32() + watchosArm64() + tvosSimulatorArm64() + tvosX64() + tvosArm64() + iosArm64() + + // Tier 3 + mingwX64() + // https://github.com/square/okio/issues/1242#issuecomment-1759357336 + if (doesNotDependOnOkio(project)) { + androidNativeArm32() + androidNativeArm64() + androidNativeX86() + androidNativeX64() + watchosDeviceArm64() + + // Deprecated, but not removed + linuxArm32Hfp() + } + +} + +fun doesNotDependOnOkio(project: Project): Boolean { + return !project.name.contains("json-okio") && !project.name.contains("json-tests") +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts b/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts new file mode 100644 index 000000000..0d535ef24 --- /dev/null +++ b/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts @@ -0,0 +1,224 @@ +import groovy.util.* +import org.gradle.jvm.tasks.Jar +import org.gradle.kotlin.dsl.* +import org.gradle.plugins.signing.* +import org.jetbrains.kotlin.gradle.dsl.* +import org.jetbrains.kotlin.gradle.tasks.* +import java.net.* + +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +// Configures publishing of Maven artifacts to MavenCentral +plugins { + `maven-publish` + signing +} + +val isMultiplatform = name in listOf("kotlinx-serialization-core", "kotlinx-serialization-json", "kotlinx-serialization-json-okio", + "kotlinx-serialization-json-tests", "kotlinx-serialization-protobuf", "kotlinx-serialization-cbor", + "kotlinx-serialization-properties") + +val isBom = name == "kotlinx-serialization-bom" + +if (!isBom) { + tasks.register("stubJavadoc") { + archiveClassifier = "javadoc" + } +} + +tasks.register("emptyJar") + +afterEvaluate { + val mainSourcesJar = tasks.register("mainSourcesJar") { + archiveClassifier = "sources" + if (isMultiplatform) { + from(kotlinExtension.sourceSets.getByName("commonMain").kotlin) + } else if (isBom) { + // no-op: sourceSets is [] for BOM, as it does not have sources. + } else { + from(sourceSets.named("main").get().allSource) + } + } + + publishing { + if (!isMultiplatform && !isBom) { + publications.withType().all { + artifactId = project.name + from(components["java"]) + artifact(mainSourcesJar) + artifact(tasks.named("stubJavadoc")) + } + } else { + // Rename artifacts for backward compatibility + publications.withType(MavenPublication::class).all { + val type = name + logger.info("Configuring $type") + when (type) { + "kotlinMultiplatform" -> { + // With Kotlin 1.4.0, the root module ID has no suffix, but for compatibility with + // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it + artifactId = project.name + reconfigureMultiplatformPublication(publications.getByName("jvm") as MavenPublication) + } + "metadata", "jvm", "js", "native" -> artifactId = "${project.name}-$type" + } + logger.info("Artifact id = $artifactId") + + // The 'root' module publishes the JVM module's Javadoc JAR as per reconfigureMultiplatformPublication, and + // every other module should publish an empty Javadoc JAR. TODO: provide proper documentation artifacts? + if (name != "kotlinMultiplatform" && !isBom) { + artifact(tasks.named("stubJavadoc")) + } + } + } + + publications.withType(MavenPublication::class).all { + pom.configureMavenCentralMetadata(project) + signPublicationIfKeyPresent(project, this) + } + } +} + +publishing { + repositories { + configureMavenPublication(this, project) + } +} + +tasks.withType().configureEach { + dependsOn(tasks.withType()) +} + +// NOTE: This is a temporary WA, see KT-61313. +// Task ':compileTestKotlin' uses this output of task ':signPublication' without declaring an explicit or implicit dependency +tasks.withType().matching { it.name.startsWith("compileTestKotlin") }.configureEach { + val targetName = name.substringAfter("compileTestKotlin") + mustRunAfter(tasks.withType().named { it == "sign${targetName}Publication" }) +} + +// NOTE: This is a temporary WA, see KT-61313. +// Task ':linkDebugTest' uses this output of task ':signPublication' without declaring an explicit or implicit dependency +tasks.withType() { + val targetName = name.substringAfter("linkDebugTest") + mustRunAfter(tasks.withType().named { it == "sign${targetName}Publication" }) +} + +// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload +tasks.register("bintrayUpload") { + dependsOn(tasks.publish) + // This is required for K/N publishing + dependsOn(tasks.publishToMavenLocal) +} + +fun MavenPom.configureMavenCentralMetadata(project: Project) { + name = project.name + description = "Kotlin multiplatform serialization runtime library" + url = "https://github.com/Kotlin/kotlinx.serialization" + + licenses { + license { + name = "The Apache Software License, Version 2.0" + url = "https://www.apache.org/licenses/LICENSE-2.0.txt" + distribution = "repo" + } + } + + developers { + developer { + id = "JetBrains" + name = "JetBrains Team" + organization = "JetBrains" + organizationUrl = "https://www.jetbrains.com" + } + } + + scm { + url = "https://github.com/Kotlin/kotlinx.serialization" + } +} + +// utility functions + +/** + * Re-configure common publication to depend on JVM artifact only in pom.xml. + * + * Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module + * metadata can still get the platform artifact and transitive dependencies from the POM. + * + * Taken from https://github.com/Kotlin/kotlinx.coroutines + */ +public fun Project.reconfigureMultiplatformPublication(jvmPublication: MavenPublication) { + val mavenPublications = + extensions.getByType(PublishingExtension::class.java).publications.withType() + val kmpPublication = mavenPublications.getByName("kotlinMultiplatform") + + var jvmPublicationXml: XmlProvider? = null + jvmPublication.pom.withXml { jvmPublicationXml = this } + + kmpPublication.pom.withXml { + val root = asNode() + // Remove the original content and add the content from the platform POM: + root.children().toList().forEach { root.remove(it as Node) } + jvmPublicationXml!!.asNode().children().forEach { root.append(it as Node) } + + // Adjust the self artifact ID, as it should match the root module's coordinates: + ((root["artifactId"] as NodeList).first() as Node).setValue(kmpPublication.artifactId) + + // Set packaging to POM to indicate that there's no artifact: + root.appendNode("packaging", "pom") + + // Remove the original platform dependencies and add a single dependency on the platform module: + val dependencies = (root["dependencies"] as NodeList).first() as Node + dependencies.children().toList().forEach { dependencies.remove(it as Node) } + dependencies.appendNode("dependency").apply { + appendNode("groupId", jvmPublication.groupId) + appendNode("artifactId", jvmPublication.artifactId) + appendNode("version", jvmPublication.version) + appendNode("scope", "compile") + } + } + + // TODO verify if this is still relevant + tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach { + @Suppress("DEPRECATION") + dependsOn("generatePomFileFor${jvmPublication.name.capitalize()}Publication") + } +} + +fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) { + val keyId = project.getSensitiveProperty("libs.sign.key.id") + val signingKey = project.getSensitiveProperty("libs.sign.key.private") + val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase") + if (!signingKey.isNullOrBlank()) { + project.extensions.configure("signing") { + useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) + sign(publication) + } + } +} + +fun configureMavenPublication(rh: RepositoryHandler, project: Project) { + rh.maven { + url = mavenRepositoryUri() + credentials { + username = project.getSensitiveProperty("libs.sonatype.user") + password = project.getSensitiveProperty("libs.sonatype.password") + } + } +} + +fun mavenRepositoryUri(): URI { + // TODO -SNAPSHOT detection can be made here as well + val repositoryId: String? = System.getenv("libs.repository.id") + return if (repositoryId == null) { + URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + } else { + URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId") + } +} + +fun Project.getSensitiveProperty(name: String): String? { + return project.findProperty(name) as? String ?: System.getenv(name) +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/setupJavaPlugin.kt b/buildSrc/src/main/kotlin/setupJavaPlugin.kt deleted file mode 100644 index 40db563d6..000000000 --- a/buildSrc/src/main/kotlin/setupJavaPlugin.kt +++ /dev/null @@ -1,42 +0,0 @@ -import org.gradle.api.* -import org.gradle.api.file.* -import org.gradle.api.plugins.* -import org.gradle.api.tasks.* -import org.gradle.api.tasks.testing.* -import org.gradle.jvm.tasks.* -import org.jetbrains.kotlin.gradle.plugin.* - -/* - * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -object JavaPluginUtil { - - @JvmStatic - fun Project.applyJavaPlugin() { - plugins.apply("java") - - plugins.withId("org.jetbrains.kotlin.multiplatform") { - listOf( - JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, - JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME - ).forEach { outputConfigurationName -> - configurations.findByName(outputConfigurationName)?.isCanBeConsumed = false - } - - disableJavaPluginTasks(extensions.getByName("sourceSets") as SourceSetContainer) - } - } -} - -private fun Project.disableJavaPluginTasks(javaSourceSet: SourceSetContainer) { - project.tasks.withType(Jar::class.java).named(javaSourceSet.getByName("main").jarTaskName).configure { - dependsOn("jvmTest") - enabled = false - } - - project.tasks.withType(Test::class.java).named(JavaPlugin.TEST_TASK_NAME) { - dependsOn("jvmJar") - enabled = false - } -} diff --git a/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts b/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts new file mode 100644 index 000000000..4b9ac756e --- /dev/null +++ b/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts @@ -0,0 +1,187 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +@file:OptIn(ExperimentalWasmDsl::class) + +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.plugin.mpp.* +import org.jetbrains.kotlin.gradle.targets.js.dsl.* +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension +import org.jetbrains.kotlin.gradle.targets.native.tasks.* +import org.jetbrains.kotlin.gradle.testing.* + +plugins { + kotlin("multiplatform") +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } +} + +tasks.withType().configureEach { + options.release = 8 +} + +// Unfortunately there is no compatible version of okio for Wasm WASI target, so we need to skip to configure WASI for json-okio and json-tests. +// json-tests uses okio with incorporate with other formatter tests so it is hard and not worth to separate it for two projects for WASI. +// So we disable WASI target in it and we hope, that WASI version of compiler and serialization plugin are identical to the WasmJS target so WASI target is being covered. +val isOkIoOrFormatTests = (name == "kotlinx-serialization-json-okio" || name == "kotlinx-serialization-json-tests") + +kotlin { + explicitApi() + + jvm { + withJava() + compilations.configureEach { + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs += "-Xjdk-release=1.8" + } + } + } + + js { + nodejs { + testTask { + useMocha { + timeout = "10s" + } + } + } + compilations.matching { it.name == "main" || it.name == "test" }.configureEach { + kotlinOptions { + sourceMap = true + moduleKind = "umd" + } + } + } + + wasmJs { + nodejs() + } + + if (!isOkIoOrFormatTests) { + wasmWasi { + nodejs() + } + } + + sourceSets.all { + kotlin.srcDirs("$name/src") + resources.srcDirs("$name/resources") + languageSettings { + progressiveMode = true + + optIn("kotlin.ExperimentalMultiplatform") + optIn("kotlin.ExperimentalStdlibApi") + optIn("kotlinx.serialization.InternalSerializationApi") + } + } + + sourceSets { + commonMain { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + + commonTest { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-common") + api("org.jetbrains.kotlin:kotlin-test-annotations-common") + } + } + + jvmMain { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib") + } + } + + jvmTest { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-junit") + } + } + + jsMain { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-js") + } + } + + jsTest { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-js") + } + } + + register("wasmMain") { + dependsOn(commonMain.get()) + } + register("wasmTest") { + dependsOn(commonTest.get()) + } + + named("wasmJsMain") { + dependsOn(named("wasmMain").get()) + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-wasm-js") + } + } + + named("wasmJsTest") { + dependsOn(named("wasmTest").get()) + dependencies { + api("org.jetbrains.kotlin:kotlin-test-wasm-js") + } + } + + if (!isOkIoOrFormatTests) { + named("wasmWasiMain") { + dependsOn(named("wasmMain").get()) + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi") + } + } + + named("wasmWasiTest") { + dependsOn(named("wasmTest").get()) + dependencies { + api("org.jetbrains.kotlin:kotlin-test-wasm-wasi") + } + } + } + } + + sourceSets.matching({ it.name.contains("Test") }).configureEach { + languageSettings { + optIn("kotlinx.serialization.InternalSerializationApi") + optIn("kotlinx.serialization.ExperimentalSerializationApi") + } + } + + targets.all { + compilations.all { + kotlinOptions { + if (overriddenLanguageVersion != null) { + languageVersion = overriddenLanguageVersion + freeCompilerArgs += "-Xsuppress-version-warnings" + } + freeCompilerArgs += "-Xexpect-actual-classes" + } + } + compilations["main"].kotlinOptions { + allWarningsAsErrors = true + } + } +} + +rootProject.extensions.configure() { + // canary nodejs that supports recent Wasm GC changes + nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts b/buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts new file mode 100644 index 000000000..47e2882f2 --- /dev/null +++ b/buildSrc/src/main/kotlin/teamcity-conventions.gradle.kts @@ -0,0 +1,16 @@ +/* + * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.gradle.kotlin.dsl.* + +val teamcitySuffix = findProperty("teamcitySuffix")?.toString() +if (teamcityInteractionEnabled && hasProperty("teamcity") && !propertyIsTrue("build_snapshot_train")) { + // Tell teamcity about version number + val postfix = if (teamcitySuffix == null) "" else " ($teamcitySuffix)" + println("##teamcity[buildNumber '${project.version}${postfix}']") + + gradle.taskGraph.beforeTask { + println("##teamcity[progressMessage 'Gradle: ${path}:${name}']") + } +} diff --git a/core/build.gradle b/core/build.gradle.kts similarity index 61% rename from core/build.gradle rename to core/build.gradle.kts index f52837acb..096923628 100644 --- a/core/build.gradle +++ b/core/build.gradle.kts @@ -1,23 +1,26 @@ -import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import Java9Modularity.configureJava9ModuleInfo +import org.jetbrains.kotlin.gradle.targets.js.ir.* /* * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -apply plugin: 'kotlin-multiplatform' -apply plugin: 'kotlinx-serialization' +plugins { + kotlin("multiplatform") + alias(libs.plugins.serialization) -apply from: rootProject.file("gradle/native-targets.gradle") -apply from: rootProject.file("gradle/configure-source-sets.gradle") + id("native-targets-conventions") + id("source-sets-conventions") +} kotlin { sourceSets { jvmTest { dependencies { - implementation 'io.kotlintest:kotlintest:2.0.7' - implementation 'com.google.guava:guava:24.1.1-jre' - implementation 'com.google.code.gson:gson:2.8.5' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" + implementation(libs.kotlintest) + implementation(libs.guava.get24()) + implementation(libs.gson) + implementation(libs.coroutines.core) } } } @@ -36,22 +39,22 @@ kotlin { may unexpectedly break old compilers, so it is left out as a safety net. Compiler plugins, starting from 1.4 are instructed to reject runtime if runtime's Require-Kotlin-Version is greater then the current compiler. */ -tasks.withType(Jar).named(kotlin.jvm().artifactsTaskName) { +tasks.withType().named(kotlin.jvm().artifactsTaskName) { // adding the ProGuard rules to the jar - from(rootProject.file("rules/common.pro")) { + from(rootDir.resolve("rules/common.pro")) { rename { "kotlinx-serialization-common.pro" } into("META-INF/proguard") } - from(rootProject.file("rules/common.pro")) { + from(rootDir.resolve("rules/common.pro")) { rename { "kotlinx-serialization-common.pro" } into("META-INF/com.android.tools/proguard") } - from(rootProject.file("rules/common.pro")) { + from(rootDir.resolve("rules/common.pro")) { rename { "kotlinx-serialization-common.pro" } into("META-INF/com.android.tools/r8") } - from(rootProject.file("rules/r8.pro")) { + from(rootDir.resolve("rules/r8.pro")) { rename { "kotlinx-serialization-r8.pro" } into("META-INF/com.android.tools/r8") } @@ -59,14 +62,14 @@ tasks.withType(Jar).named(kotlin.jvm().artifactsTaskName) { manifest { attributes( - "Implementation-Version": version, - "Require-Kotlin-Version": "1.4.30-M1", + "Implementation-Version" to version, + "Require-Kotlin-Version" to "1.4.30-M1", ) } } -Java9Modularity.configureJava9ModuleInfo(project) +configureJava9ModuleInfo() -tasks.withType(org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink.class).configureEach { +tasks.withType().configureEach { kotlinOptions.freeCompilerArgs += "-Xwasm-enable-array-range-checks" } diff --git a/formats/cbor/build.gradle b/formats/cbor/build.gradle deleted file mode 100644 index 4dbcc273b..000000000 --- a/formats/cbor/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'kotlin-multiplatform' -apply plugin: 'kotlinx-serialization' -apply from: rootProject.file("gradle/native-targets.gradle") -apply from: rootProject.file("gradle/configure-source-sets.gradle") - -kotlin { - - sourceSets { - commonMain { - dependencies { - api project(":kotlinx-serialization-core") - } - } - - jvmTest { - dependencies { - implementation 'io.kotlintest:kotlintest:2.0.7' - implementation 'com.upokecenter:cbor:4.2.0' - implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version" - implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version" - implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version" - implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:$jackson_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" - } - } - } -} - -Java9Modularity.configureJava9ModuleInfo(project) diff --git a/formats/cbor/build.gradle.kts b/formats/cbor/build.gradle.kts new file mode 100644 index 000000000..5b3c7ff5e --- /dev/null +++ b/formats/cbor/build.gradle.kts @@ -0,0 +1,38 @@ +import Java9Modularity.configureJava9ModuleInfo + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + kotlin("multiplatform") + alias(libs.plugins.serialization) + + id("native-targets-conventions") + id("source-sets-conventions") +} + +kotlin { + + sourceSets { + commonMain { + dependencies { + api(project(":kotlinx-serialization-core")) + } + } + + jvmTest { + dependencies { + implementation(libs.kotlintest) + implementation(libs.cbor) + implementation(libs.jackson.core) + implementation(libs.jackson.databind) + implementation(libs.jackson.module.kotlin) + implementation(libs.jackson.cbor) + implementation(libs.coroutines.core) + } + } + } +} + +configureJava9ModuleInfo() diff --git a/formats/hocon/build.gradle b/formats/hocon/build.gradle deleted file mode 100644 index c5fae36eb..000000000 --- a/formats/hocon/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.KotlinVersion -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'kotlin' -apply plugin: 'kotlinx-serialization' - -compileKotlin { - kotlinOptions { - allWarningsAsErrors = true - jvmTarget = '1.8' - } -} - -tasks.withType(KotlinCompile).configureEach { - kotlinOptions { - if (rootProject.ext.kotlin_lv_override != null) { - languageVersion = rootProject.ext.kotlin_lv_override - freeCompilerArgs += "-Xsuppress-version-warnings" - } - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - - -dependencies { - api project(':kotlinx-serialization-core') - api 'org.jetbrains.kotlin:kotlin-stdlib' - api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' - - api 'com.typesafe:config:1.4.1' - - testImplementation 'org.jetbrains.kotlin:kotlin-test' - testImplementation 'junit:junit:4.12' -} - -Java9Modularity.configureJava9ModuleInfo(project) diff --git a/formats/hocon/build.gradle.kts b/formats/hocon/build.gradle.kts new file mode 100644 index 000000000..5f0ae2ceb --- /dev/null +++ b/formats/hocon/build.gradle.kts @@ -0,0 +1,53 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import Java9Modularity.configureJava9ModuleInfo +import org.jetbrains.kotlin.gradle.dsl.* + + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + kotlin("jvm") + alias(libs.plugins.serialization) +} + +tasks.compileKotlin { + compilerOptions { + allWarningsAsErrors = true + } +} + +tasks.withType().configureEach { + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 + } +} + +tasks.withType().configureEach { + kotlinOptions { + if (overriddenLanguageVersion != null) { + languageVersion = overriddenLanguageVersion + freeCompilerArgs += "-Xsuppress-version-warnings" + } + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + + +dependencies { + api(project(":kotlinx-serialization-core")) + api("org.jetbrains.kotlin:kotlin-stdlib") + api("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + + api(libs.typesafe.config) + + testImplementation("org.jetbrains.kotlin:kotlin-test") + testImplementation(libs.junit.junit4) +} + +configureJava9ModuleInfo() diff --git a/formats/json-okio/build.gradle.kts b/formats/json-okio/build.gradle.kts index a51fff032..ef24caf7c 100644 --- a/formats/json-okio/build.gradle.kts +++ b/formats/json-okio/build.gradle.kts @@ -7,11 +7,12 @@ import java.net.* plugins { kotlin("multiplatform") - kotlin("plugin.serialization") + alias(libs.plugins.serialization) + + id("native-targets-conventions") + id("source-sets-conventions") } -apply(from = rootProject.file("gradle/native-targets.gradle")) -apply(from = rootProject.file("gradle/configure-source-sets.gradle")) kotlin { sourceSets { @@ -25,12 +26,12 @@ kotlin { dependencies { api(project(":kotlinx-serialization-core")) api(project(":kotlinx-serialization-json")) - implementation("com.squareup.okio:okio:${property("okio_version")}") + implementation(libs.okio) } } val commonTest by getting { dependencies { - implementation("com.squareup.okio:okio:${property("okio_version")}") + implementation(libs.okio) } } } diff --git a/formats/json-tests/build.gradle.kts b/formats/json-tests/build.gradle.kts index 6be0a3a79..31f4e46e0 100644 --- a/formats/json-tests/build.gradle.kts +++ b/formats/json-tests/build.gradle.kts @@ -6,11 +6,11 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.* plugins { kotlin("multiplatform") - kotlin("plugin.serialization") -} + alias(libs.plugins.serialization) -apply(from = rootProject.file("gradle/native-targets.gradle")) -apply(from = rootProject.file("gradle/configure-source-sets.gradle")) + id("native-targets-conventions") + id("source-sets-conventions") +} // disable kover tasks because there are no non-test classes in the project tasks.named("koverHtmlReport") { @@ -35,14 +35,14 @@ kotlin { dependencies { api(project(":kotlinx-serialization-json")) api(project(":kotlinx-serialization-json-okio")) - implementation("com.squareup.okio:okio:${property("okio_version")}") + implementation(libs.okio) } } val jvmTest by getting { dependencies { - implementation("com.google.code.gson:gson:2.8.5") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${property("coroutines_version")}") + implementation(libs.gson) + implementation(libs.coroutines.core) } } } diff --git a/formats/json/build.gradle b/formats/json/build.gradle.kts similarity index 52% rename from formats/json/build.gradle rename to formats/json/build.gradle.kts index d35bcb5dc..db48d9556 100644 --- a/formats/json/build.gradle +++ b/formats/json/build.gradle.kts @@ -1,13 +1,17 @@ -import static KotlinVersion.isKotlinVersionAtLeast +import Java9Modularity.configureJava9ModuleInfo +import org.jetbrains.kotlin.gradle.tasks.* /* * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -apply plugin: 'kotlin-multiplatform' -apply plugin: 'kotlinx-serialization' -apply from: rootProject.file("gradle/native-targets.gradle") -apply from: rootProject.file("gradle/configure-source-sets.gradle") +plugins { + kotlin("multiplatform") + alias(libs.plugins.serialization) + + id("native-targets-conventions") + id("source-sets-conventions") +} // disable kover tasks because there are no tests in the project tasks.named("koverHtmlReport") { @@ -30,29 +34,29 @@ kotlin { } commonMain { dependencies { - api project(":kotlinx-serialization-core") + api(project(":kotlinx-serialization-core")) } } - jsWasmMain { - dependsOn(sourceSets.commonMain) + register("jsWasmMain") { + dependsOn(commonMain.get()) } - jsMain { - dependsOn(sourceSets.jsWasmMain) + named("jsMain") { + dependsOn(named("jsWasmMain").get()) } - wasmJsMain { - dependsOn(sourceSets.jsWasmMain) + named("wasmJsMain") { + dependsOn(named("jsWasmMain").get()) } - wasmWasiMain { - dependsOn(sourceSets.jsWasmMain) + named("wasmWasiMain") { + dependsOn(named("jsWasmMain").get()) } } } -Java9Modularity.configureJava9ModuleInfo(project) - // This task should be disabled because of no need to build and publish intermediate JsWasm sourceset -tasks.whenTaskAdded { task -> - if (task.name == 'compileJsWasmMainKotlinMetadata') { - task.enabled = false +tasks.whenTaskAdded { + if (name == "compileJsWasmMainKotlinMetadata") { + enabled = false } } + +configureJava9ModuleInfo() diff --git a/formats/properties/build.gradle b/formats/properties/build.gradle deleted file mode 100644 index dd77ce52f..000000000 --- a/formats/properties/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'kotlin-multiplatform' -apply plugin: 'kotlinx-serialization' -apply from: rootProject.file("gradle/native-targets.gradle") -apply from: rootProject.file("gradle/configure-source-sets.gradle") - - -kotlin { - - sourceSets { - commonMain { - dependencies { - api project(":kotlinx-serialization-core") - } - } - - jvmTest { - dependencies { - implementation 'io.kotlintest:kotlintest:2.0.7' - implementation 'com.upokecenter:cbor:4.0.0-beta1' - implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version" - implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version" - implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version" - implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:$jackson_version" - } - } - } -} - -Java9Modularity.configureJava9ModuleInfo(project) diff --git a/formats/properties/build.gradle.kts b/formats/properties/build.gradle.kts new file mode 100644 index 000000000..20c8ea9c9 --- /dev/null +++ b/formats/properties/build.gradle.kts @@ -0,0 +1,38 @@ +import Java9Modularity.configureJava9ModuleInfo + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + kotlin("multiplatform") + + alias(libs.plugins.serialization) + + id("native-targets-conventions") + id("source-sets-conventions") +} + +kotlin { + + sourceSets { + commonMain { + dependencies { + api(project(":kotlinx-serialization-core")) + } + } + + jvmTest { + dependencies { + implementation(libs.kotlintest) + implementation(libs.cbor) + implementation(libs.jackson.core) + implementation(libs.jackson.databind) + implementation(libs.jackson.module.kotlin) + implementation(libs.jackson.cbor) + } + } + } +} + +configureJava9ModuleInfo() diff --git a/formats/protobuf/build.gradle b/formats/protobuf/build.gradle deleted file mode 100644 index 9f93b18fc..000000000 --- a/formats/protobuf/build.gradle +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'java' // Needed for protobuf plugin only -apply plugin: 'kotlin-multiplatform' -apply plugin: 'kotlinx-serialization' -apply plugin: 'com.google.protobuf' -apply from: rootProject.file("gradle/native-targets.gradle") -apply from: rootProject.file("gradle/configure-source-sets.gradle") - -protobuf { - protoc { - // Download from repositories - artifact = 'com.google.protobuf:protoc:3.17.3' - } -} - -clean { - delete protobuf.generatedFilesBaseDir -} - -kotlin { - sourceSets { - configureEach { - languageSettings.optIn("kotlinx.serialization.internal.CoreFriendModuleApi") - } - - commonMain { - dependencies { - api project(":kotlinx-serialization-core") - } - } - - jvmTest { - kotlin.srcDirs += file("${protobuf.generatedFilesBaseDir}/test/java") - dependencies { - implementation 'com.google.protobuf:protobuf-java:3.17.3' - implementation 'io.kotlintest:kotlintest:2.0.7' - } - } - } -} - -sourceSets.test.proto { - srcDirs = ['testProto', 'jvmTest/resources/common'] -} - -compileTestKotlinJvm { - dependsOn 'generateTestProto' -} - -Java9Modularity.configureJava9ModuleInfo(project) diff --git a/formats/protobuf/build.gradle.kts b/formats/protobuf/build.gradle.kts new file mode 100644 index 000000000..1ff991dfb --- /dev/null +++ b/formats/protobuf/build.gradle.kts @@ -0,0 +1,63 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +import Java9Modularity.configureJava9ModuleInfo +import com.google.protobuf.gradle.* +import org.gradle.kotlin.dsl.protobuf + +plugins { + java // Needed for protobuf plugin only + kotlin("multiplatform") + + alias(libs.plugins.serialization) + alias(libs.plugins.protobuf) + + id("native-targets-conventions") + id("source-sets-conventions") +} + +protobuf { + protobuf.protoc { + // Download from repositories + artifact = libs.protoc.get().toString() + } +} + +tasks.clean { + delete(protobuf.protobuf.generatedFilesBaseDir) +} + +kotlin { + sourceSets { + configureEach { + languageSettings.optIn("kotlinx.serialization.internal.CoreFriendModuleApi") + } + + commonMain { + dependencies { + api(project(":kotlinx-serialization-core")) + } + } + + jvmTest { + kotlin.srcDirs(file("${protobuf.protobuf.generatedFilesBaseDir}/test/java")) + + dependencies { + implementation(libs.protobuf.java) + implementation(libs.kotlintest) + } + } + } +} + +sourceSets.test { + extensions.configure("proto") { + srcDirs("testProto", "jvmTest/resources/common") + } +} + +tasks.compileTestKotlinJvm { + dependsOn("generateTestProto") +} + +configureJava9ModuleInfo() diff --git a/gradle.properties b/gradle.properties index 2174b418f..9ccf242b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,22 +5,12 @@ group=org.jetbrains.kotlinx version=1.7.0-SNAPSHOT -kotlin.version=1.9.22 - # This version takes precedence if 'bootstrap' property passed to project kotlin.version.snapshot=2.0.255-SNAPSHOT # Also set KONAN_LOCAL_DIST environment variable in bootstrap mode to auto-assign konan.home -junit_version=4.12 -jackson_version=2.10.0.pr1 -dokka_version=1.9.10 native.deploy= -validator_version=0.15.0-Beta.2 -knit_version=0.5.0 # Only for tests -coroutines_version=1.6.4 -kover_version=0.8.0-Beta2 -okio_version=3.6.0 kover.enabled=true diff --git a/gradle/benchmark-parsing.gradle b/gradle/benchmark-parsing.gradle deleted file mode 100644 index b09ef9987..000000000 --- a/gradle/benchmark-parsing.gradle +++ /dev/null @@ -1,26 +0,0 @@ -import groovy.json.JsonSlurper -import org.gradle.api.* - -/** - * Utility for printing benchmark results. - * Results can be obtained with JMH flags - * -rf json -rff serialization-benchmark-results.json - */ -class PrintBenchmarksTask extends DefaultTask { - private String fileName = "serialization-benchmark-results.json" - - @TaskAction - def printBenchmarkJsonAsTeamcityStats() { - File jsonFile = project.file(fileName) - if (!jsonFile.exists()) throw new TaskExecutionException(this, new FileNotFoundException("File $fileName not found")) - def parsedJson = new JsonSlurper().parseText(jsonFile.text) - - parsedJson.each { v -> - def name = (v.benchmark - "kotlinx.benchmarks.") - def score = v.primaryMetric.score - println("##teamcity[buildStatisticValue key='" + name + "' value='" + score + "']") - } - } -} - -rootProject.tasks.register("printBenchmarksJsonAsTeamcityStats", PrintBenchmarksTask) diff --git a/gradle/compiler-version.gradle b/gradle/compiler-version.gradle deleted file mode 100644 index b95452929..000000000 --- a/gradle/compiler-version.gradle +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -gradle.taskGraph.whenReady { - println("Using Kotlin compiler version: $compilerVersion") - if (build_snapshot_train) { - configure(subprojects.findAll { it.name == "core" }) { - configurations.matching { it.name == "kotlinCompilerClasspath" }.all { - println "Manifest of kotlin-compiler-embeddable.jar for serialization" - resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each { - def manifest = zipTree(it).matching { - include 'META-INF/MANIFEST.MF' - }.getFiles().first() - - manifest.readLines().each { - println it - } - } - } - } - } -} diff --git a/gradle/configure-source-sets.gradle b/gradle/configure-source-sets.gradle deleted file mode 100644 index f744b1712..000000000 --- a/gradle/configure-source-sets.gradle +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import static KotlinVersion.* - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } -} - -tasks.withType(JavaCompile).configureEach { - options.release = 8 -} - -// Unfortunately there is no compatible version of okio for Wasm WASI target, so we need to skip to configure WASI for json-okio and json-tests. -// json-tests uses okio with incorporate with other formatter tests so it is hard and not worth to separate it for two projects for WASI. -// So we disable WASI target in it and we hope, that WASI version of compiler and serialization plugin are identical to the WasmJS target so WASI target is being covered. -Boolean isOkIoOrFormatTests = (project.name == 'kotlinx-serialization-json-okio' || project.name == 'kotlinx-serialization-json-tests') - -kotlin { - jvm { - withJava() - compilations.configureEach { - kotlinOptions { - jvmTarget = '1.8' - freeCompilerArgs += '-Xjdk-release=1.8' - } - } - } - - js { - nodejs { - testTask { - useMocha { - timeout = "10s" - } - } - } - configure([compilations.main, compilations.test]) { - kotlinOptions { - sourceMap = true - moduleKind = "umd" - } - } - } - - wasmJs { - nodejs() - } - - if (!isOkIoOrFormatTests) { - wasmWasi { - nodejs() - } - } - - sourceSets.all { - kotlin.srcDirs = ["$it.name/src"] - resources.srcDirs = ["$it.name/resources"] - languageSettings { - progressiveMode = true - - optIn("kotlin.ExperimentalMultiplatform") - optIn("kotlin.ExperimentalStdlibApi") - optIn("kotlinx.serialization.InternalSerializationApi") - } - } - - sourceSets { - commonMain { - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-common' - } - } - - commonTest { - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-common' - api 'org.jetbrains.kotlin:kotlin-test-annotations-common' - } - } - - jvmMain { - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib' - } - } - - jvmTest { - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-junit' - } - } - - jsMain { - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-js' - } - } - - jsTest { - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-js' - } - } - - create("wasmMain") { - dependsOn(commonMain) - } - create("wasmTest") { - dependsOn(commonTest) - } - - wasmJsMain { - dependsOn(wasmMain) - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js' - } - } - - wasmJsTest { - dependsOn(wasmTest) - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-wasm-js' - } - } - - if (!isOkIoOrFormatTests) { - wasmWasiMain { - dependsOn(wasmMain) - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi' - } - } - - wasmWasiTest { - dependsOn(wasmTest) - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-wasm-wasi' - } - } - } - - nativeMain.dependencies { - } - } - - sourceSets.findAll({ it.name.contains("Test") }).forEach { srcSet -> - srcSet.languageSettings { - it.optIn("kotlinx.serialization.InternalSerializationApi") - it.optIn("kotlinx.serialization.ExperimentalSerializationApi") - } - } - - sourceSets.matching({ it.name.contains("Main") }).all { srcSet -> - project.ext.set("kotlin.mpp.freeCompilerArgsForSourceSet.${srcSet.name}", ["-Xexplicit-api=strict"]) - } - - targets.all { - compilations.all { - kotlinOptions { - if (rootProject.ext.kotlin_lv_override != null) { - languageVersion = rootProject.ext.kotlin_lv_override - freeCompilerArgs += "-Xsuppress-version-warnings" - } - freeCompilerArgs += "-Xexpect-actual-classes" - } - } - compilations.main { - kotlinOptions { - allWarningsAsErrors = true - } - } - } - - def targetsWithoutTestRunners = ["linuxArm64", "linuxArm32Hfp"] - configure(targets) { - // Configure additional binaries to run tests in the background - if (["macos", "linux", "mingw"].any { name.startsWith(it) && !targetsWithoutTestRunners.contains(name) }) { - binaries { - test("background", [nativeDebugBuild]) { - freeCompilerArgs += ["-trw"] - } - } - testRuns { - background { setExecutionSourceFrom(binaries.backgroundDebugTest) } - } - } - } -} - -rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with { - // canary nodejs that supports recent Wasm GC changes - it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" - it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" -} \ No newline at end of file diff --git a/gradle/dokka.gradle b/gradle/dokka.gradle deleted file mode 100644 index 5a208f2b1..000000000 --- a/gradle/dokka.gradle +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'kotlin' -apply plugin: 'org.jetbrains.dokka' - -def documentedSubprojects = ["kotlinx-serialization-core", - "kotlinx-serialization-json", - "kotlinx-serialization-json-okio", - "kotlinx-serialization-cbor", - "kotlinx-serialization-properties", - "kotlinx-serialization-hocon", - "kotlinx-serialization-protobuf"] - -subprojects { - if (!(name in documentedSubprojects)) return - apply plugin: 'org.jetbrains.dokka' - dependencies { - dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version") - } - - tasks.named('dokkaHtmlPartial') { - outputDirectory = file("build/dokka") - pluginsMapConfiguration.set(["org.jetbrains.dokka.base.DokkaBase": """{ "templatesDir": "${rootProject.projectDir.toString().replace('\\', '/')}/dokka-templates" }"""]) - - dokkaSourceSets { - configureEach { - includes.from(rootProject.file('dokka/moduledoc.md').path) - - perPackageOption { - matchingRegex.set("kotlinx\\.serialization(\$|\\.).*") - reportUndocumented.set(true) - skipDeprecated.set(true) - } - - // Internal API - perPackageOption { - matchingRegex.set("kotlinx\\.serialization.internal(\$|\\.).*") - suppress.set(true) - } - - // Internal JSON API - perPackageOption { - matchingRegex.set("kotlinx\\.serialization.json.internal(\$|\\.).*") - suppress.set(true) - reportUndocumented.set(false) - } - - // Workaround for typealias - perPackageOption { - matchingRegex.set("kotlinx\\.serialization.protobuf.internal(\$|\\.).*") - suppress.set(true) - reportUndocumented.set(false) - } - - // Deprecated migrations - perPackageOption { - matchingRegex.set("kotlinx\\.protobuf(\$|\\.).*") - reportUndocumented.set(true) - skipDeprecated.set(true) - } - - // Deprecated migrations - perPackageOption { - matchingRegex.set("org\\.jetbrains\\.kotlinx\\.serialization\\.config(\$|\\.).*") - reportUndocumented.set(false) - skipDeprecated.set(true) - } - - // JS/Native implementation of JVM-only `org.intellij.lang.annotations.Language` class to add syntax support by IDE. - perPackageOption { - matchingRegex.set("org\\.intellij\\.lang\\.annotations(\$|\\.).*") - suppress.set(true) - } - - sourceLink { - localDirectory.set(rootDir) - remoteUrl.set(new URL("https://github.com/Kotlin/kotlinx.serialization/tree/master")) - remoteLineSuffix.set("#L") - } - } - } - } -} - -// Knit relies on Dokka task and it's pretty convenient -task dokka(dependsOn: dokkaHtmlMultiModule) {} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..b0b3bd6e6 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,55 @@ +[versions] +kotlin = "1.9.22" +kover = "0.8.0-Beta2" +dokka = "1.9.20" +knit = "0.5.0" +bcv = "0.15.0-Beta.2" +animalsniffer = "1.7.1" +protobuf = "0.8.19" +shadow = "8.1.1" +jmh = "0.7.2" +jmh-core = "1.37" +guava = "31.1-jre" +guava24 = "24.1.1-jre" +jackson = "2.13.3" +okio = "3.6.0" +gson = "2.8.5" +kotlintest = "2.0.7" +coroutines = "1.6.4" +cbor = "4.2.0" +typesafe-config = "1.4.1" +junit4 = "4.12" +protoc = "3.17.3" + +[libraries] +gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin"} +gradlePlugin-kover = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kover"} +gradlePlugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka"} +gradlePlugin-animalsniffer = { module = "ru.vyarus:gradle-animalsniffer-plugin", version.ref = "animalsniffer"} +gradlePlugin-binaryCompatibilityValidator = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "bcv"} + +dokka-pathsaver = { module = "org.jetbrains.kotlinx:dokka-pathsaver-plugin", version.ref = "knit"} +knitTest = { module = "org.jetbrains.kotlinx:kotlinx-knit-test", version.ref = "knit"} +jmhCore = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh-core"} +guava = { module = "com.google.guava:guava", version.ref = "guava"} +guava-24 = { module = "com.google.guava:guava", version.ref = "guava24"} +jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson"} +jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson"} +jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson"} +jackson-cbor = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor", version.ref = "jackson"} +okio = { module = "com.squareup.okio:okio", version.ref = "okio"} +gson = { module = "com.google.code.gson:gson", version.ref = "gson"} +kotlintest = { module = "io.kotlintest:kotlintest", version.ref = "kotlintest"} +coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines"} +cbor = { module = "com.upokecenter:cbor", version.ref = "cbor"} +typesafe-config = { module = "com.typesafe:config", version.ref = "typesafe-config"} +junit-junit4 = { module = "junit:junit", version.ref = "junit4"} +protoc = { module = "com.google.protobuf:protoc", version.ref = "protoc"} +protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protoc" } + +[plugins] +knit = { id = "org.jetbrains.kotlinx.knit", version.ref = "knit" } +jmh = { id = "me.champeau.jmh", version.ref = "jmh" } +shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } +protobuf = { id = "com.google.protobuf", version.ref = "protobuf" } +serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } diff --git a/gradle/maven-metadata.gradle b/gradle/maven-metadata.gradle deleted file mode 100644 index 5e4148cc5..000000000 --- a/gradle/maven-metadata.gradle +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -project.ext.pomConfig = { - licenses { - license { - name "The Apache Software License, Version 2.0" - url "http://www.apache.org/licenses/LICENSE-2.0.txt" - distribution "repo" - } - } - developers { - developer { - id "JetBrains" - name "JetBrains Team" - organization "JetBrains" - organizationUrl "http://www.jetbrains.com" - } - } - - scm { - url "https://github.com/Kotlin/kotlinx.serialization" - } -} - -project.ext.configureMavenCentralMetadata = { pom -> - def root = asNode() - root.appendNode('name', project.name) - root.appendNode('description', 'Kotlin multiplatform serialization runtime library') - root.appendNode('url', 'https://github.com/Kotlin/kotlinx.serialization') - root.children().last() + pomConfig -} diff --git a/gradle/native-targets.gradle b/gradle/native-targets.gradle deleted file mode 100644 index 8ef7f48d1..000000000 --- a/gradle/native-targets.gradle +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -static def doesNotDependOnOkio(project) { - return !project.name.contains("json-okio") && !project.name.contains("json-tests") -} - -kotlin { - applyDefaultHierarchyTemplate { - - // According to https://kotlinlang.org/docs/native-target-support.html - // Tier 1 - macosX64() - macosArm64() - iosSimulatorArm64() - iosX64() - - // Tier 2 - linuxX64() - linuxArm64() - watchosSimulatorArm64() - watchosX64() - watchosArm32() - watchosArm64() - tvosSimulatorArm64() - tvosX64() - tvosArm64() - iosArm64() - - // Tier 3 - mingwX64() - // https://github.com/square/okio/issues/1242#issuecomment-1759357336 - if (doesNotDependOnOkio(project)) { - androidNativeArm32() - androidNativeArm64() - androidNativeX86() - androidNativeX64() - watchosDeviceArm64() - - // Deprecated, but not removed - linuxArm32Hfp() - } - } -} diff --git a/gradle/publish-mpp-root-module-in-platform.gradle b/gradle/publish-mpp-root-module-in-platform.gradle deleted file mode 100644 index 7362ffb4a..000000000 --- a/gradle/publish-mpp-root-module-in-platform.gradle +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - - -/** - * Publish the platform JAR and POM so that consumers who depend on this module and can't read Gradle module - * metadata can still get the platform artifact and transitive dependencies from the POM - * (see details in https://youtrack.jetbrains.com/issue/KT-39184#focus=streamItem-27-4115233.0-0) - */ -project.ext.publishPlatformArtifactsInRootModule = { MavenPublication platformPublication -> - afterEvaluate { - XmlProvider platformXml = null - - platformPublication.pom.withXml { platformXml = it } - - publishing.publications.kotlinMultiplatform { - pom.withXml { - Node root = asNode() - // Remove the original content and add the content from the platform POM: - root.children().toList().each { root.remove(it as Node) } - platformXml.asNode().children().each { root.append(it as Node) } - - // Adjust the self artifact ID, as it should match the root module's coordinates: - ((root.get("artifactId") as NodeList).get(0) as Node).setValue(artifactId) - - // Set packaging to POM to indicate that there's no artifact: - root.appendNode("packaging", "pom") - - // Remove the original platform dependencies and add a single dependency on the platform module: - Node dependencies = (root.get("dependencies") as NodeList).get(0) as Node - dependencies.children().toList().each { dependencies.remove(it as Node) } - Node singleDependency = dependencies.appendNode("dependency") - singleDependency.appendNode("groupId", platformPublication.groupId) - singleDependency.appendNode("artifactId", platformPublication.artifactId) - singleDependency.appendNode("version", platformPublication.version) - singleDependency.appendNode("scope", "compile") - } - } - - tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach { - dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) - } - } -} \ No newline at end of file diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle deleted file mode 100644 index 2c3518e2b..000000000 --- a/gradle/publishing.gradle +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -// Configures publishing of Maven artifacts to MavenCentral - -apply plugin: 'maven-publish' -apply plugin: 'signing' - -apply from: project.rootProject.file('gradle/maven-metadata.gradle') - -def isMultiplatform = project.name in ["kotlinx-serialization-core", "kotlinx-serialization-json", "kotlinx-serialization-json-okio", - "kotlinx-serialization-json-tests", "kotlinx-serialization-protobuf", "kotlinx-serialization-cbor", - "kotlinx-serialization-properties"] -def isBom = project.name == "kotlinx-serialization-bom" - -if (!isBom) { - task stubSources(type: Jar) { - archiveClassifier = 'sources' - } - - task stubJavadoc(type: Jar) { - archiveClassifier = 'javadoc' - } -} - -task emptyJar(type: Jar) { -} - -afterEvaluate { - task mainSourcesJar(type: Jar) { - classifier = 'sources' - if (isMultiplatform) { - from kotlin.sourceSets.commonMain.kotlin - } else if (isBom) { - // no-op: sourceSets is [] for BOM, as it does not have sources. - } else { - from sourceSets.main.allSource - } - } -} - -afterEvaluate { - publishing { - def variantName = "${project.name}" - - if (!isMultiplatform && !isBom) { - publications { - maven(MavenPublication) { publication -> - artifactId variantName - publication.from components.java - publication.artifact mainSourcesJar - artifact stubJavadoc - - PublishingKt.configureMavenCentralMetadata(publication.pom, project) - PublishingKt.signPublicationIfKeyPresent(project, publication) - } - } - - return - } - - // Rename artifacts for backward compatibility - publications.all { - def type = it.name - logger.info("Configuring $type") - switch (type) { - case 'kotlinMultiplatform': - // With Kotlin 1.4.0, the root module ID has no suffix, but for compatibility with - // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it - it.artifactId = variantName - apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle" - publishPlatformArtifactsInRootModule(publications["jvm"]) - break - case 'metadata': - case 'jvm': - case 'js': - it.artifactId = "$variantName-$type" - break - } - logger.info("Artifact id = ${it.artifactId}") - - PublishingKt.configureMavenCentralMetadata(pom, project) - PublishingKt.signPublicationIfKeyPresent(project, it) - - // The 'root' module publishes the JVM module's Javadoc JAR as per publishPlatformArtifactsInRootModule, and - // every other module should publish an empty Javadoc JAR. TODO: provide proper documentation artifacts? - if (name != "kotlinMultiplatform" && !isBom) { - artifact stubJavadoc - } - } - } -} - -publishing { - repositories { - PublishingKt.configureMavenPublication(delegate, project) - } -} - -// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload -task bintrayUpload(dependsOn: publish) - -// This is required for K/N publishing -bintrayUpload.dependsOn publishToMavenLocal - diff --git a/gradle/teamcity.gradle b/gradle/teamcity.gradle deleted file mode 100644 index 950494d99..000000000 --- a/gradle/teamcity.gradle +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -def teamcitySuffix = project.findProperty("teamcitySuffix")?.toString() -if (!teamcityInteractionDisabled && project.hasProperty("teamcity") && !(build_snapshot_train || rootProject.properties['build_snapshot_up'])) { - // Tell teamcity about version number - def postfix = (teamcitySuffix == null) ? "" : " ($teamcitySuffix)" - println("##teamcity[buildNumber '${project.version}${postfix}']") - - gradle.taskGraph.beforeTask { - println("##teamcity[progressMessage 'Gradle: ${it.project.path}:${it.name}']") - } -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2..e6441136f 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 31cca4913..b82aa23a4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c78733..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# 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 "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ 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. 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=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,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" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..7101f8e46 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +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 @@ -56,11 +57,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 @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/guide/build.gradle b/guide/build.gradle deleted file mode 100644 index b4261e811..000000000 --- a/guide/build.gradle +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/* - * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -apply plugin: 'kotlin' -apply plugin: 'kotlinx-serialization' - -kotlin { - jvmToolchain(8) -} - -tasks.withType(KotlinCompile).configureEach { - kotlinOptions { - if (rootProject.ext.kotlin_lv_override != null) { - languageVersion = rootProject.ext.kotlin_lv_override - freeCompilerArgs += "-Xsuppress-version-warnings" - } - } -} - -dependencies { - testImplementation "org.jetbrains.kotlin:kotlin-test-junit" - testImplementation "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version" - testImplementation project(":kotlinx-serialization-core") - testImplementation project(":kotlinx-serialization-json") - testImplementation project(":kotlinx-serialization-cbor") - testImplementation project(":kotlinx-serialization-protobuf") - testImplementation project(":kotlinx-serialization-properties") -} - -sourceSets.test { - java.srcDirs("example", "test") -} diff --git a/guide/build.gradle.kts b/guide/build.gradle.kts new file mode 100644 index 000000000..9df47bcf5 --- /dev/null +++ b/guide/build.gradle.kts @@ -0,0 +1,37 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +/* + * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + kotlin("jvm") + alias(libs.plugins.serialization) +} + +kotlin { + jvmToolchain(8) +} + +tasks.withType().configureEach { + kotlinOptions { + if (overriddenLanguageVersion != null) { + languageVersion = overriddenLanguageVersion + freeCompilerArgs += "-Xsuppress-version-warnings" + } + } +} + +dependencies { + testImplementation(libs.knitTest) + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") + testImplementation(project(":kotlinx-serialization-core")) + testImplementation(project(":kotlinx-serialization-json")) + testImplementation(project(":kotlinx-serialization-cbor")) + testImplementation(project(":kotlinx-serialization-protobuf")) + testImplementation(project(":kotlinx-serialization-properties")) +} + +sourceSets.test { + java.srcDirs("example", "test") +} diff --git a/integration-test/build.gradle b/integration-test/build.gradle deleted file mode 100644 index 6c4e700f3..000000000 --- a/integration-test/build.gradle +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ -buildscript { - ext.serialization_version = mainLibVersion - - repositories { - mavenCentral() - maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" } - mavenLocal() { - mavenContent { - snapshotsOnly() - } - } - } -} - -// Versions substituted in settings.gradle -plugins { - id 'org.jetbrains.kotlin.multiplatform' version '0' - id 'org.jetbrains.kotlin.plugin.serialization' version '0' - id 'org.jetbrains.kotlin.kapt' version '0' -} - -repositories { - mavenCentral() - maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" } - mavenLocal() { - mavenContent { - snapshotsOnly() - } - } -} - -group 'com.example' -version '0.0.1' - -apply plugin: 'maven-publish' - -kotlin { - // Switching module kind for JS is required to run tests - js { - nodejs {} - configure([compilations.main, compilations.test]) { - kotlinOptions { - sourceMap = true - moduleKind = "umd" - } - } - } - wasmJs { - nodejs() - } - wasmWasi { - nodejs() - } - jvm { - withJava() - } - macosX64() - macosArm64() - linuxX64() - mingwX64() - - sourceSets { - all { - languageSettings { - optIn('kotlinx.serialization.ExperimentalSerializationApi') - } - } - - commonMain { - dependencies { - implementation kotlin('stdlib') - implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$serialization_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serialization_version" - } - } - commonTest { - dependencies { - implementation kotlin('test-common') - implementation kotlin('test-annotations-common') - } - } - jvmMain { - dependencies { - implementation kotlin('stdlib-jdk8') - implementation 'com.google.dagger:dagger:2.13' - } - } - jvmTest { - dependencies { - implementation kotlin('test') - implementation kotlin('test-junit') - } - } - jsMain { - dependencies { - implementation kotlin('stdlib-js') - - } - } - jsTest { - dependencies { - implementation kotlin('test-js') - } - } - wasmJsMain { - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js' - } - } - wasmJsTest { - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-wasm-js' - } - } - wasmWasiMain { - dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi' - } - } - wasmWasiTest { - dependencies { - api 'org.jetbrains.kotlin:kotlin-test-wasm-wasi' - } - } - } - - targets.all { - compilations.all { - kotlinOptions { - freeCompilerArgs += "-Xexpect-actual-classes" - } - } - compilations.main { - kotlinOptions { - allWarningsAsErrors = true - } - } - } -} - -dependencies { - kapt 'com.google.dagger:dagger-compiler:2.13' -} - -task run dependsOn "check" - -rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with { - // canary nodejs that supports recent Wasm GC changes - it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" - it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" -} - -tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach { - args.add("--ignore-engines") -} diff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.kts new file mode 100644 index 000000000..638cea148 --- /dev/null +++ b/integration-test/build.gradle.kts @@ -0,0 +1,147 @@ +/* + * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension +import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask + +val serialization_version = property("mainLibVersion") as String + +// Versions substituted in settings.gradle.kts +plugins { + id("org.jetbrains.kotlin.multiplatform") version "0" + id("org.jetbrains.kotlin.plugin.serialization") version "0" + id("org.jetbrains.kotlin.kapt") version "0" + + id("maven-publish") +} + +repositories { + mavenCentral() + maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") + mavenLocal { + mavenContent { + snapshotsOnly() + } + } +} + +group = "com.example" +version = "0.0.1" + +kotlin { + // Switching module kind for JS is required to run tests + js { + nodejs {} + compilations.matching { it.name == "main" || it.name == "test" }.configureEach { + kotlinOptions { + sourceMap = true + moduleKind = "umd" + } + } + } + wasmJs { + nodejs() + } + wasmWasi { + nodejs() + } + jvm { + withJava() + } + macosX64() + macosArm64() + linuxX64() + mingwX64() + + sourceSets { + all { + languageSettings { + optIn("kotlinx.serialization.ExperimentalSerializationApi") + } + } + + commonMain { + dependencies { + implementation(kotlin("stdlib")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$serialization_version") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serialization_version") + } + } + commonTest { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + jvmMain { + dependencies { + implementation(kotlin("stdlib-jdk8")) + implementation("com.google.dagger:dagger:2.13") + } + } + jvmTest { + dependencies { + implementation(kotlin("test")) + implementation(kotlin("test-junit")) + } + } + jsMain { + dependencies { + implementation(kotlin("stdlib-js")) + + } + } + jsTest { + dependencies { + implementation(kotlin("test-js")) + } + } + named("wasmJsMain") { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-wasm-js") + } + } + named("wasmJsTest") { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-wasm-js") + } + } + named("wasmWasiMain") { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi") + } + } + named("wasmWasiTest") { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-wasm-wasi") + } + } + } + + targets.all { + compilations.all { + kotlinOptions { + freeCompilerArgs += "-Xexpect-actual-classes" + } + } + compilations["main"].kotlinOptions { + allWarningsAsErrors = true + } + } +} + +dependencies { + "kapt"("com.google.dagger:dagger-compiler:2.13") +} + +rootProject.extensions.configure { + // canary nodejs that supports recent Wasm GC changes + nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} + +tasks.withType().configureEach { + args.add("--ignore-engines") +} diff --git a/integration-test/settings.gradle b/integration-test/settings.gradle.kts similarity index 68% rename from integration-test/settings.gradle rename to integration-test/settings.gradle.kts index f8cb2d871..c2cb0c46f 100644 --- a/integration-test/settings.gradle +++ b/integration-test/settings.gradle.kts @@ -1,5 +1,6 @@ pluginManagement { resolutionStrategy { + val mainKotlinVersion: String by settings eachPlugin { if (requested.id.id == "org.jetbrains.kotlin.multiplatform") { useVersion("$mainKotlinVersion") @@ -15,10 +16,10 @@ pluginManagement { repositories { mavenCentral() - maven { url 'https://plugins.gradle.org/m2/' } - maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" } + maven("https://plugins.gradle.org/m2/") + maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") mavenLocal() } } -rootProject.name = 'kotlinx-serialization-integration-test' +rootProject.name = "kotlinx-serialization-integration-test" diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index ed5256ee9..000000000 --- a/settings.gradle +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} - -rootProject.name = 'kotlinx-serialization' - -include ':kotlinx-serialization-core' -project(':kotlinx-serialization-core').projectDir = file('./core') - -include ':kotlinx-serialization-bom' -project(':kotlinx-serialization-bom').projectDir = file('./bom') - -include ':kotlinx-serialization-json' -project(':kotlinx-serialization-json').projectDir = file('./formats/json') - -include ':kotlinx-serialization-json-okio' -project(':kotlinx-serialization-json-okio').projectDir = file('./formats/json-okio') - -include ':kotlinx-serialization-json-tests' -project(':kotlinx-serialization-json-tests').projectDir = file('./formats/json-tests') - -include ':kotlinx-serialization-protobuf' -project(':kotlinx-serialization-protobuf').projectDir = file('./formats/protobuf') - -include ':kotlinx-serialization-cbor' -project(':kotlinx-serialization-cbor').projectDir = file('./formats/cbor') - -include ':kotlinx-serialization-hocon' -project(':kotlinx-serialization-hocon').projectDir = file('./formats/hocon') - -include ':kotlinx-serialization-properties' -project(':kotlinx-serialization-properties').projectDir = file('./formats/properties') - -include ':benchmark' -project(':benchmark').projectDir = file('./benchmark') - -include ':guide' -project(':guide').projectDir = file('./guide') diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..ca4e340a9 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,110 @@ +/* + * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +pluginManagement { + repositories { + /** + * Overrides for Teamcity 'K2 User Projects' + 'Aggregate build / Kotlinx libraries compilation' configuration: + * kotlin_repo_url - local repository with snapshot Kotlin compiler + * kotlin_version - kotlin version to use + * kotlin_language_version - LV to use + */ + val kotlinRepoUrl: String? = providers.gradleProperty("kotlin_repo_url").orNull + if (kotlinRepoUrl?.isNotEmpty() == true) { + maven(kotlinRepoUrl) + } + /* + * This property group is used to build kotlinx.serialization against Kotlin compiler snapshot. + * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version. + * DO NOT change the name of these properties without adapting kotlinx.train build chain. + */ + val buildSnapshotTrain: String? = providers.gradleProperty("build_snapshot_train").orNull + if (buildSnapshotTrain.equals("true", true)) { + maven("https://oss.sonatype.org/content/repositories/snapshots") + } + + // kotlin-dev with space redirector + maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") + + maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") + // For Dokka that depends on kotlinx-html + maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") + + gradlePluginPortal() + mavenCentral() + mavenLocal() + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" +} + +rootProject.name = "kotlinx-serialization" + +include(":kotlinx-serialization-core") +project(":kotlinx-serialization-core").projectDir = file("./core") + +include(":kotlinx-serialization-bom") +project(":kotlinx-serialization-bom").projectDir = file("./bom") + +include(":kotlinx-serialization-json") +project(":kotlinx-serialization-json").projectDir = file("./formats/json") + +include(":kotlinx-serialization-json-okio") +project(":kotlinx-serialization-json-okio").projectDir = file("./formats/json-okio") + +include(":kotlinx-serialization-json-tests") +project(":kotlinx-serialization-json-tests").projectDir = file("./formats/json-tests") + +include(":kotlinx-serialization-protobuf") +project(":kotlinx-serialization-protobuf").projectDir = file("./formats/protobuf") + +include(":kotlinx-serialization-cbor") +project(":kotlinx-serialization-cbor").projectDir = file("./formats/cbor") + +include(":kotlinx-serialization-hocon") +project(":kotlinx-serialization-hocon").projectDir = file("./formats/hocon") + +include(":kotlinx-serialization-properties") +project(":kotlinx-serialization-properties").projectDir = file("./formats/properties") + +include(":benchmark") +project(":benchmark").projectDir = file("./benchmark") + +include(":guide") +project(":guide").projectDir = file("./guide") + + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + overriddenKotlinVersion()?.also { overriddenVersion -> + logger.info("Overriding Kotlin version: $overriddenVersion") + version("kotlin", overriddenVersion) + } + } + } +} + +fun overriddenKotlinVersion(): String? { + val kotlinRepoUrl: String? = providers.gradleProperty("kotlin_repo_url").orNull + val repoVersion: String? = providers.gradleProperty("kotlin_version").orNull + + val bootstrap: String? = providers.gradleProperty("bootstrap").orNull + val bootstrapVersion: String? = providers.gradleProperty("kotlin.version.snapshot").orNull + + val buildSnapshotTrain: String? = providers.gradleProperty("build_snapshot_train").orNull + val trainVersion: String? = providers.gradleProperty("kotlin_snapshot_version").orNull + + if (kotlinRepoUrl?.isNotEmpty() == true) { + return repoVersion ?: throw IllegalArgumentException("\"kotlin_version\" Gradle property should be defined") + } else if (bootstrap != null) { + return bootstrapVersion ?: throw IllegalArgumentException("\"kotlin.version.snapshot\" Gradle property should be defined") + } + if (buildSnapshotTrain?.isNotEmpty() == true) { + return trainVersion ?: throw IllegalArgumentException("\"kotlin_snapshot_version\" should be defined when building with snapshot compiler") + } + return null +} \ No newline at end of file