xref: /aosp_15_r20/external/kotlinx.serialization/build.gradle (revision 57b5a4a64c534cf7f27ac9427ceab07f3d8ed3d8)
1/*
2 * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5buildscript {
6    /**
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")) {
20        ext.kotlin_version = property('kotlin.version.snapshot')
21        ext["kotlin.native.home"] = System.getenv("KONAN_LOCAL_DIST")
22    } else {
23        ext.kotlin_version = property('kotlin.version')
24    }
25    if (project.hasProperty("library.version")) {
26        ext.overriden_version = property('library.version')
27    }
28    ext.experimentalsEnabled = ["-progressive",
29                                "-opt-in=kotlin.ExperimentalMultiplatform",
30                                "-opt-in=kotlinx.serialization.InternalSerializationApi",
31                                "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
32    ]
33
34    ext.experimentalsInTestEnabled = ["-progressive",
35                                      "-opt-in=kotlin.ExperimentalMultiplatform",
36                                      "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
37                                      "-opt-in=kotlinx.serialization.InternalSerializationApi",
38                                      "-P", "plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false"
39    ]
40    ext.koverEnabled = property('kover.enabled') ?: true
41
42    def noTeamcityInteractionFlag = rootProject.hasProperty("no_teamcity_interaction")
43    def buildSnapshotUPFlag = rootProject.hasProperty("build_snapshot_up")
44    ext.teamcityInteractionDisabled = noTeamcityInteractionFlag || buildSnapshotUPFlag
45
46    /*
47    * This property group is used to build kotlinx.serialization against Kotlin compiler snapshot.
48    * 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 {
59            maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
60        }
61    }
62
63    repositories {
64        maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
65        // kotlin-dev with space redirector
66        maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
67        mavenCentral()
68        gradlePluginPortal()
69        // For Dokka that depends on kotlinx-html
70        maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
71        mavenLocal()
72    }
73
74    configurations.classpath {
75        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
76            if (details.requested.group == 'org.jetbrains.kotlin') {
77                details.useVersion kotlin_version
78            }
79        }
80    }
81
82    dependencies {
83        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
84        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
85        classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
86        classpath "org.jetbrains.kotlinx:kover:$kover_version"
87        classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$validator_version"
88        classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
89        classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.5.3' // Android API check
90
91        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
92
93        // Various benchmarking stuff
94        classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
95        classpath "me.champeau.jmh:jmh-gradle-plugin:0.6.6"
96    }
97}
98
99// To make it visible for compiler-version.gradle
100ext.compilerVersion = org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION
101ext.nativeDebugBuild = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
102
103apply plugin: 'binary-compatibility-validator'
104apply plugin: 'base'
105apply plugin: 'kotlinx-knit'
106
107apiValidation {
108    ignoredProjects += ["benchmark", "guide", "kotlinx-serialization"]
109}
110
111knit {
112    siteRoot = "https://kotlinlang.org/api/kotlinx.serialization"
113    moduleDocs = "build/dokka/htmlMultiModule"
114}
115
116// Build API docs for all modules with dokka before running Knit
117knitPrepare.dependsOn "dokka"
118
119apply plugin: 'org.jetbrains.dokka'
120dependencies {
121    dokkaPlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
122}
123
124allprojects {
125    group 'org.jetbrains.kotlinx'
126
127    def deployVersion = properties['DeployVersion']
128    if (deployVersion != null) version = deployVersion
129
130    if (project.hasProperty("bootstrap")) {
131        version = version + '-SNAPSHOT'
132    }
133
134    // the only place where HostManager could be instantiated
135    project.ext.hostManager = new org.jetbrains.kotlin.konan.target.HostManager()
136
137    if (build_snapshot_train) {
138        // Snapshot-specific
139        repositories {
140            mavenLocal()
141            maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
142        }
143    }
144
145    if (snapshotRepoUrl != null && snapshotRepoUrl != "") {
146        // Snapshot-specific for K2 CI configurations
147        repositories {
148            maven { url snapshotRepoUrl }
149        }
150    }
151
152    configurations.all {
153        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
154            if (details.requested.group == 'org.jetbrains.kotlin') {
155                details.useVersion kotlin_version
156            }
157        }
158    }
159
160    repositories {
161        mavenCentral()
162        maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
163        // 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
166        maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
167        // For local development
168        mavenLocal()
169
170    }
171
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    }
178}
179
180def 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
184subprojects {
185    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
193    apply from: rootProject.file('gradle/teamcity.gradle')
194    // Configure publishing for some artifacts
195    if (!unpublishedProjects.contains(project.name)) {
196        apply from: rootProject.file('gradle/publishing.gradle')
197    }
198}
199
200subprojects {
201    // Can't be applied to BOM
202    if (excludedFromBomProjects.contains(project.name)) return
203
204    // Animalsniffer setup
205    // 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)
210    apply plugin: 'ru.vyarus.animalsniffer'
211
212    afterEvaluate { // Can be applied only when the project is evaluated
213        animalsniffer {
214            sourceSets = [sourceSets.main]
215            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
227        }
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        }
232
233        // 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
242    apply from: rootProject.file("gradle/kover.gradle")
243}
244
245apply from: rootProject.file('gradle/compiler-version.gradle')
246apply from: rootProject.file("gradle/dokka.gradle")
247apply from: rootProject.file("gradle/benchmark-parsing.gradle")
248
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}