aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
blob: 09a62feaf96be49b9ae11cdc3ebdb78b35af10e5 (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
/*
 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

import org.jetbrains.kotlin.konan.target.HostManager

buildscript {
    /*
     * These property group is used to build kotlinx.atomicfu against Kotlin compiler snapshot.
     * How does it work:
     * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
     * Additionally, mavenLocal and Sonatype snapshots are added to repository list (the former is required for AFU and public
     * the latter is required for compiler snapshots).
     * 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 {
            mavenLocal()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        }
    }
    // These two flags are enabled in train builds for JVM IR compiler testing
    ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
    ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null

    repositories {
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
        // Future replacement for kotlin-dev, with cache redirector
        maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
        maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
    }
    
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
    }
}

allprojects {
    // the only place where HostManager could be instantiated
    project.ext.hostManager = new HostManager()
    if (build_snapshot_train) {
        kotlin_version = rootProject.properties['kotlin_snapshot_version']
        repositories {
            mavenLocal()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        }
    }

    println "Using Kotlin $kotlin_version for project $it"
    repositories {
        jcenter()
        // Future replacement for kotlin-dev, with cache redirector
        maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
        maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
    }

    def deployVersion = properties['DeployVersion']
    if (deployVersion != null) version = deployVersion

    // 'atomicfu-native' check is a kludge so that existing YouTrack config works, todo: remove
    if (project != rootProject && project.name != 'atomicfu-native') {
        apply from: rootProject.file("gradle/publishing.gradle")
    }

    // This fixes "org.gradle.jvm.version" in Gradle metadata
    plugins.withType(JavaPlugin) {
        java {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    }
}

println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
if (build_snapshot_train) {
    afterEvaluate {
        println "Manifest of kotlin-compiler-embeddable.jar for atomicfu"
        configure(subprojects.findAll { it.name == "atomicfu" }) {
            configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
                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
                    }
                }
            }
        }
    }
}

// main deployment task
task deploy(dependsOn: getTasksByName("publish", true) + getTasksByName("publishNpm", true))