summaryrefslogtreecommitdiff
path: root/build.gradle
blob: 34765ef25671e272b83dd05a677a128cf056ed0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * 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:$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"]
}

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"] 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")
}