summaryrefslogtreecommitdiff
path: root/gradle/configure-source-sets.gradle
blob: e7888eea51455278c19246883beced90fd9134f1 (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
/*
 * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

kotlin {
    jvm {
        withJava()
        configure([compilations.main, compilations.test]) {
            kotlinOptions {
                jvmTarget = '1.6'
                freeCompilerArgs += "-Xsuppress-deprecated-jvm-target-warning"
            }
        }
    }

    js {
        nodejs {}
        configure([compilations.main, compilations.test]) {
            kotlinOptions {
                sourceMap = true
                moduleKind = "umd"
                metaInfo = true
            }
        }
    }

    sourceSets.all {
        kotlin.srcDirs = ["$it.name/src"]
        resources.srcDirs = ["$it.name/resources"]
        languageSettings {
            progressiveMode = true

            optIn("kotlin.Experimental")
            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'
            }
        }

        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.main {
            kotlinOptions {
                allWarningsAsErrors = true
            }
        }
    }

    def targetsWithoutTestRunners = ["linuxArm32Hfp", "linuxArm64", "mingwX86"]
    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) }
            }
        }
    }
}