blob: 34765ef25671e272b83dd05a677a128cf056ed0e [file] [log] [blame]
Roman Elizarov26af9192017-09-21 18:12:04 +03001/*
Clara Fok93e18122024-04-23 10:28:10 -07002 * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov26af9192017-09-21 18:12:04 +03003 */
4
Leonid Startsev08d3ca02017-07-26 15:16:23 +03005buildscript {
Clara Fok93e18122024-04-23 10:28:10 -07006 /**
7 * Overrides for Teamcity 'K2 User Projects' + 'Aggregate build / Kotlinx libraries compilation' configuration:
8 * kotlin_repo_url - local repository with snapshot Kotlin compiler
9 * kotlin_version - kotlin version to use
10 * kotlin_language_version - LV to use
11 */
12 ext.snapshotRepoUrl = rootProject.properties["kotlin_repo_url"]
13 ext.kotlin_lv_override = rootProject.properties["kotlin_language_version"]
14 if (snapshotRepoUrl != null && snapshotRepoUrl != "") {
15 ext.kotlin_version = rootProject.properties["kotlin_version"]
16 repositories {
17 maven { url snapshotRepoUrl }
18 }
19 } else if (project.hasProperty("bootstrap")) {
Leonid Startsev45aa7c72019-04-23 21:29:03 +030020 ext.kotlin_version = property('kotlin.version.snapshot')
Leonid Startsevcea9b432019-11-19 14:14:26 +030021 ext["kotlin.native.home"] = System.getenv("KONAN_LOCAL_DIST")
Leonid Startsevca620912017-11-09 19:55:51 +030022 } else {
Leonid Startsev45aa7c72019-04-23 21:29:03 +030023 ext.kotlin_version = property('kotlin.version')
Leonid Startsevca620912017-11-09 19:55:51 +030024 }
Leonid Startsev78d5d2d2019-07-25 13:51:54 +030025 if (project.hasProperty("library.version")) {
26 ext.overriden_version = property('library.version')
27 }
Clara Fok93e18122024-04-23 10:28:10 -070028 ext.experimentalsEnabled = ["-progressive",
Leonid Startsev9650a282022-05-11 14:55:47 +030029 "-opt-in=kotlin.ExperimentalMultiplatform",
Clara Fok93e18122024-04-23 10:28:10 -070030 "-opt-in=kotlinx.serialization.InternalSerializationApi",
31 "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
Vsevolod Tolstopyatov74b48022019-04-02 18:56:29 +030032 ]
Leonid Startsevc1bb4d22018-10-23 18:50:39 +030033
Clara Fok93e18122024-04-23 10:28:10 -070034 ext.experimentalsInTestEnabled = ["-progressive",
Leonid Startsev9650a282022-05-11 14:55:47 +030035 "-opt-in=kotlin.ExperimentalMultiplatform",
36 "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
37 "-opt-in=kotlinx.serialization.InternalSerializationApi",
Clara Fok93e18122024-04-23 10:28:10 -070038 "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
Vsevolod Tolstopyatov74b48022019-04-02 18:56:29 +030039 ]
Leonid Startseve721ebe2021-10-29 14:41:49 +030040 ext.koverEnabled = property('kover.enabled') ?: true
Leonid Startsev08d3ca02017-07-26 15:16:23 +030041
Clara Fok93e18122024-04-23 10:28:10 -070042 def noTeamcityInteractionFlag = rootProject.hasProperty("no_teamcity_interaction")
43 def buildSnapshotUPFlag = rootProject.hasProperty("build_snapshot_up")
44 ext.teamcityInteractionDisabled = noTeamcityInteractionFlag || buildSnapshotUPFlag
45
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +030046 /*
Leonid Startsevcea9b432019-11-19 14:14:26 +030047 * This property group is used to build kotlinx.serialization against Kotlin compiler snapshot.
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +030048 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version.
49 * DO NOT change the name of these properties without adapting kotlinx.train build chain.
50 */
51 def prop = rootProject.properties['build_snapshot_train']
52 ext.build_snapshot_train = prop != null && prop != ""
53 if (build_snapshot_train) {
54 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
55 if (kotlin_version == null) {
56 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
57 }
58 repositories {
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +030059 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +030060 }
61 }
62
Leonid Startsev08d3ca02017-07-26 15:16:23 +030063 repositories {
Vsevolod Tolstopyatovd3d2dca2020-10-03 06:18:32 -070064 maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
Leonid Startsevfc9343f2021-04-26 15:18:02 +030065 // kotlin-dev with space redirector
66 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Leonid Startsev6a8dc862021-02-04 17:03:31 +030067 mavenCentral()
Leonid Startsev45aa7c72019-04-23 21:29:03 +030068 gradlePluginPortal()
Vsevolod Tolstopyatov6d2e5cf2021-03-17 15:00:40 +030069 // For Dokka that depends on kotlinx-html
Leonid Startsev9f8d0502021-07-08 12:12:06 +030070 maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
Leonid Startsev0e75d252021-09-01 15:07:44 +030071 mavenLocal()
Leonid Startsev08d3ca02017-07-26 15:16:23 +030072 }
73
Leonid Startsevd656e5a2019-06-14 12:06:23 +030074 configurations.classpath {
75 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
76 if (details.requested.group == 'org.jetbrains.kotlin') {
77 details.useVersion kotlin_version
78 }
79 }
80 }
81
Leonid Startsev08d3ca02017-07-26 15:16:23 +030082 dependencies {
Leonid Startsev45aa7c72019-04-23 21:29:03 +030083 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
84 classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
Leonid Startsevbc9c8f42020-04-06 22:30:25 +030085 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Leonid Startseve721ebe2021-10-29 14:41:49 +030086 classpath "org.jetbrains.kotlinx:kover:$kover_version"
Vsevolod Tolstopyatov6de96482020-06-17 06:41:00 -070087 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$validator_version"
Roman Elizarov5459c102020-08-11 12:27:36 +030088 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +030089 classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.5.3' // Android API check
Leonid Startsevbc9c8f42020-04-06 22:30:25 +030090
Sebastian Schuberthece9fdd2022-01-28 16:23:48 +010091 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
Leonid Startsevbae49f92018-05-03 19:57:01 +030092
Leonid Startsev45aa7c72019-04-23 21:29:03 +030093 // Various benchmarking stuff
94 classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
Clara Fok93e18122024-04-23 10:28:10 -070095 classpath "me.champeau.jmh:jmh-gradle-plugin:0.6.6"
Leonid Startsev08d3ca02017-07-26 15:16:23 +030096 }
97}
98
Vsevolod Tolstopyatov608cbad2020-09-14 15:38:02 +030099// To make it visible for compiler-version.gradle
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +0300100ext.compilerVersion = org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION
Vsevolod Tolstopyatov07f730a2021-01-22 03:32:08 -0800101ext.nativeDebugBuild = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300102
Vsevolod Tolstopyatov6de96482020-06-17 06:41:00 -0700103apply plugin: 'binary-compatibility-validator'
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300104apply plugin: 'base'
105apply plugin: 'kotlinx-knit'
Leonid Startsev45aa7c72019-04-23 21:29:03 +0300106
Vsevolod Tolstopyatov6de96482020-06-17 06:41:00 -0700107apiValidation {
Roman Elizarov5459c102020-08-11 12:27:36 +0300108 ignoredProjects += ["benchmark", "guide", "kotlinx-serialization"]
Vsevolod Tolstopyatov6de96482020-06-17 06:41:00 -0700109}
Leonid Startsev00dd4f52017-08-23 16:09:21 +0300110
Roman Elizarov5459c102020-08-11 12:27:36 +0300111knit {
Clara Fok93e18122024-04-23 10:28:10 -0700112 siteRoot = "https://kotlinlang.org/api/kotlinx.serialization"
Vsevolod Tolstopyatovd3d2dca2020-10-03 06:18:32 -0700113 moduleDocs = "build/dokka/htmlMultiModule"
Roman Elizarov5459c102020-08-11 12:27:36 +0300114}
115
116// Build API docs for all modules with dokka before running Knit
117knitPrepare.dependsOn "dokka"
118
Ignat Beresnev8be68452021-12-27 18:40:50 +0300119apply plugin: 'org.jetbrains.dokka'
120dependencies {
121 dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
122}
123
Leonid Startsev00dd4f52017-08-23 16:09:21 +0300124allprojects {
125 group 'org.jetbrains.kotlinx'
Leonid Startsev476b7222018-06-26 17:06:14 +0300126
Leonid Startsevf5accd12020-02-25 20:42:46 +0300127 def deployVersion = properties['DeployVersion']
128 if (deployVersion != null) version = deployVersion
Leonid Startsev78d5d2d2019-07-25 13:51:54 +0300129
Leonid Startsev476b7222018-06-26 17:06:14 +0300130 if (project.hasProperty("bootstrap")) {
131 version = version + '-SNAPSHOT'
132 }
Leonid Startsev84062e12017-09-25 16:41:38 +0300133
Leonid Startsev9f6d3b42019-10-09 18:07:41 +0300134 // the only place where HostManager could be instantiated
135 project.ext.hostManager = new org.jetbrains.kotlin.konan.target.HostManager()
136
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +0300137 if (build_snapshot_train) {
138 // Snapshot-specific
Vsevolod Tolstopyatovfa2231c2019-05-29 17:39:15 +0300139 repositories {
140 mavenLocal()
141 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
142 }
143 }
Leonid Startsevcf1db5c2019-09-17 19:33:44 +0300144
Clara Fok93e18122024-04-23 10:28:10 -0700145 if (snapshotRepoUrl != null && snapshotRepoUrl != "") {
146 // Snapshot-specific for K2 CI configurations
147 repositories {
148 maven { url snapshotRepoUrl }
149 }
150 }
151
Leonid Startsevcf1db5c2019-09-17 19:33:44 +0300152 configurations.all {
153 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
154 if (details.requested.group == 'org.jetbrains.kotlin') {
155 details.useVersion kotlin_version
156 }
157 }
158 }
159
Leonid Startsev84062e12017-09-25 16:41:38 +0300160 repositories {
Leonid Startsev6a8dc862021-02-04 17:03:31 +0300161 mavenCentral()
Vsevolod Tolstopyatovd3d2dca2020-10-03 06:18:32 -0700162 maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
Vsevolod Tolstopyatov6d2e5cf2021-03-17 15:00:40 +0300163 // kotlin-dev with space redirector
164 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
165 // For Dokka that depends on kotlinx-html
Leonid Startsev9f8d0502021-07-08 12:12:06 +0300166 maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
Vsevolod Tolstopyatov6d2e5cf2021-03-17 15:00:40 +0300167 // For local development
168 mavenLocal()
Leonid Startsev9f8d0502021-07-08 12:12:06 +0300169
Leonid Startsev84062e12017-09-25 16:41:38 +0300170 }
Clara Fok93e18122024-04-23 10:28:10 -0700171
172 tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile).configureEach {
173 compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") }
174 }
175 tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile).configureEach {
176 compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") }
177 }
Leonid Startsev00dd4f52017-08-23 16:09:21 +0300178}
Leonid Startsev08d3ca02017-07-26 15:16:23 +0300179
Clara Fok93e18122024-04-23 10:28:10 -0700180def unpublishedProjects = ["benchmark", "guide", "kotlinx-serialization-json-tests"] as Set
181def excludedFromBomProjects = unpublishedProjects + "kotlinx-serialization-bom" as Set
182def uncoveredProjects = ["kotlinx-serialization-bom", "benchmark", "guide"] as Set
183
Leonid Startsev1c35d912017-10-04 12:26:43 +0300184subprojects {
Leonid Startsevc1bb4d22018-10-23 18:50:39 +0300185 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { task ->
186 if (task.name.contains("Test") || task.name.contains("Jmh")) {
187 task.kotlinOptions.freeCompilerArgs += experimentalsInTestEnabled
188 } else {
189 task.kotlinOptions.freeCompilerArgs += experimentalsEnabled
190 }
191 }
192
Leonid Startsev9f6d3b42019-10-09 18:07:41 +0300193 apply from: rootProject.file('gradle/teamcity.gradle')
Leonid Startsev45aa7c72019-04-23 21:29:03 +0300194 // Configure publishing for some artifacts
Clara Fok93e18122024-04-23 10:28:10 -0700195 if (!unpublishedProjects.contains(project.name)) {
Roman Elizarov5459c102020-08-11 12:27:36 +0300196 apply from: rootProject.file('gradle/publishing.gradle')
197 }
Leonid Startsev45aa7c72019-04-23 21:29:03 +0300198}
Leonid Startseved87fbd2017-08-04 17:33:09 +0300199
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300200subprojects {
201 // Can't be applied to BOM
Clara Fok93e18122024-04-23 10:28:10 -0700202 if (excludedFromBomProjects.contains(project.name)) return
Leonid Startseve721ebe2021-10-29 14:41:49 +0300203
204 // Animalsniffer setup
Clara Fok93e18122024-04-23 10:28:10 -0700205 // Animalsniffer requires java plugin to be applied, but Kotlin 1.9.20
206 // relies on `java-base` for Kotlin Multiplatforms `withJava` implementation
207 // https://github.com/xvik/gradle-animalsniffer-plugin/issues/84
208 // https://youtrack.jetbrains.com/issue/KT-59595
209 JavaPluginUtil.applyJavaPlugin(project)
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300210 apply plugin: 'ru.vyarus.animalsniffer'
211
212 afterEvaluate { // Can be applied only when the project is evaluated
213 animalsniffer {
214 sourceSets = [sourceSets.main]
Clara Fok93e18122024-04-23 10:28:10 -0700215 def annotationValue = "kotlinx.serialization.json.internal.SuppressAnimalSniffer"
216 switch (name) {
217 case "kotlinx-serialization-core":
218 annotationValue = "kotlinx.serialization.internal.SuppressAnimalSniffer"
219 break
220 case "kotlinx-serialization-hocon":
221 annotationValue = "kotlinx.serialization.hocon.internal.SuppressAnimalSniffer"
222 break
223 case "kotlinx-serialization-protobuf":
224 annotationValue = "kotlinx.serialization.protobuf.internal.SuppressAnimalSniffer"
225 }
226 annotation = annotationValue
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300227 }
228 dependencies {
229 signature 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature'
230 signature 'org.codehaus.mojo.signature:java18:1.0@signature'
231 }
Leonid Startseve721ebe2021-10-29 14:41:49 +0300232
Clara Fok93e18122024-04-23 10:28:10 -0700233 // Add dependency on kotlinx-serialization-bom inside other kotlinx-serialization modules themselves, so they have same versions
234 BomKt.addBomApiDependency(project, ":kotlinx-serialization-bom")
235 }
236}
237
238// Kover setup
239subprojects {
240 if (uncoveredProjects.contains(project.name)) return
241
Leonid Startseve721ebe2021-10-29 14:41:49 +0300242 apply from: rootProject.file("gradle/kover.gradle")
Vsevolod Tolstopyatovab5c1392021-06-09 15:38:57 +0300243}
244
Vsevolod Tolstopyatov608cbad2020-09-14 15:38:02 +0300245apply from: rootProject.file('gradle/compiler-version.gradle')
Leonid Startsevbc9c8f42020-04-06 22:30:25 +0300246apply from: rootProject.file("gradle/dokka.gradle")
Leonid Startsev98ead982021-06-28 13:02:07 +0300247apply from: rootProject.file("gradle/benchmark-parsing.gradle")
Clara Fok93e18122024-04-23 10:28:10 -0700248
249tasks.named("dokkaHtmlMultiModule") {
250 pluginsMapConfiguration.set(["org.jetbrains.dokka.base.DokkaBase": """{ "templatesDir": "${projectDir.toString().replace('\\', '/')}/dokka-templates" }"""])
251}
252
253tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach {
254 args.add("--ignore-engines")
255}