1/* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5import org.jetbrains.kotlin.konan.target.HostManager 6 7buildscript { 8 def overridingKotlinVersion = KotlinConfiguration.getOverridingKotlinVersion(project) 9 if (overridingKotlinVersion != null) { project.kotlin_version = overridingKotlinVersion } 10 11 /* 12 * This property group is used to build kotlinx.atomicfu against Kotlin compiler snapshots. 13 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version. 14 * Additionally, mavenLocal and Sonatype snapshots are added to repository list 15 * (the former is required for AFU and public, the latter is required for compiler snapshots). 16 * DO NOT change the name of these properties without adapting kotlinx.train build chain. 17 */ 18 def buildSnapshotTrainGradleProperty = project.findProperty("build_snapshot_train") 19 ext.build_snapshot_train = buildSnapshotTrainGradleProperty != null && buildSnapshotTrainGradleProperty != "" 20 if (build_snapshot_train) { 21 project.kotlin_version = project.findProperty("kotlin_snapshot_version") 22 if (project.kotlin_version == null) { 23 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with a snapshot compiler") 24 } 25 repositories { 26 maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 27 } 28 } 29 30 repositories { 31 mavenCentral() 32 gradlePluginPortal() 33 KotlinConfiguration.addCustomKotlinRepositoryIfEnabled(delegate, project) 34 } 35 36 dependencies { 37 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 38 classpath "com.github.node-gradle:gradle-node-plugin:$gradle_node_version" 39 } 40 41 ext.native_targets_enabled = !project.hasProperty("disable_native_targets") 42} 43 44plugins { 45 id 'org.jetbrains.kotlinx.binary-compatibility-validator' version '0.13.2' 46} 47 48allprojects { 49 // the only place where HostManager could be instantiated 50 project.ext.hostManager = new HostManager() 51 52 def overridingKotlinVersion = KotlinConfiguration.getOverridingKotlinVersion(project) 53 if (overridingKotlinVersion != null) { project.kotlin_version = overridingKotlinVersion } 54 55 if (build_snapshot_train) { 56 project.kotlin_version = project.findProperty("kotlin_snapshot_version") 57 repositories { 58 maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 59 } 60 } 61 62 logger.info("Using Kotlin compiler ${project.kotlin_version} for project ${project.name}") 63 64 repositories { 65 mavenCentral() 66 KotlinConfiguration.addCustomKotlinRepositoryIfEnabled(delegate, project) 67 } 68 69 def deployVersion = project.findProperty("DeployVersion") 70 if (deployVersion != null) project.version = deployVersion 71 72 // atomicfu-native check is a kludge so that existing YouTrack config works, todo: remove 73 if (project != rootProject && project.name != "atomicfu-native") { 74 apply from: rootProject.file("gradle/publishing.gradle") 75 } 76 77 // this fixes "org.gradle.jvm.version" in Gradle metadata 78 plugins.withType(JavaPlugin).configureEach { 79 java { 80 toolchain { 81 languageVersion.set(JavaLanguageVersion.of(8)) 82 } 83 } 84 } 85 86 tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile).configureEach { 87 compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } 88 } 89 tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile).configureEach { 90 compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") } 91 } 92} 93 94if (build_snapshot_train) { 95 afterEvaluate { 96 println "Manifest of kotlin-compiler-embeddable.jar for atomicfu" 97 configure(subprojects.findAll { it.name == "atomicfu" }) { 98 configurations.matching { it.name == "kotlinCompilerClasspath" }.configureEach { 99 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each { 100 def manifest = zipTree(it).matching { 101 include 'META-INF/MANIFEST.MF' 102 }.getFiles().first() 103 104 manifest.readLines().each { 105 println it 106 } 107 } 108 } 109 } 110 } 111} 112 113// main deployment task 114task deploy(dependsOn: getTasksByName("publish", true) + getTasksByName("publishNpm", true)) 115 116// Right now it is used for switching nodejs version which is supports generated wasm bytecode 117extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with { 118 // canary nodejs that supports recent Wasm GC changes 119 it.nodeVersion = '21.0.0-v8-canary202309167e82ab1fa2' 120 it.nodeDownloadBaseUrl = 'https://nodejs.org/download/v8-canary' 121} 122 123// We need to ignore unsupported engines (i.e. canary) for npm 124tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask).configureEach { 125 args.add("--ignore-engines") 126} 127