1/* 2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5apply plugin: 'kotlin-multiplatform' 6apply from: rootProject.file("gradle/targets.gradle") 7apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle") 8apply from: rootProject.file("gradle/compile-common.gradle") 9apply from: rootProject.file("gradle/compile-js-multiplatform.gradle") 10apply from: rootProject.file("gradle/compile-native-multiplatform.gradle") 11apply from: rootProject.file('gradle/publish-npm-js.gradle') 12 13/* 14 * All platform plugins and configuration magic happens here instead of build.gradle 15 * because JMV-only projects depend on core, thus core should always be initialized before configuration. 16 */ 17kotlin { 18 configure(sourceSets) { 19 def srcDir = name.endsWith('Main') ? 'src' : 'test' 20 def platform = name[0..-5] 21 kotlin.srcDir "$platform/$srcDir" 22 if (name == "jvmMain") { 23 resources.srcDirs = ["$platform/resources"] 24 } else if (name == "jvmTest") { 25 resources.srcDirs = ["$platform/test-resources"] 26 } 27 languageSettings { 28 progressiveMode = true 29 experimentalAnnotations.each { useExperimentalAnnotation(it) } 30 } 31 } 32 33 configure(targets) { 34 def targetName = it.name 35 compilations.all { compilation -> 36 def compileTask = tasks.getByName(compilation.compileKotlinTaskName) 37 // binary compatibility support 38 if (targetName.contains("jvm") && compilation.compilationName == "main") { 39 compileTask.kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"] 40 } 41 } 42 } 43} 44 45configurations { 46 configureKotlinJvmPlatform(kotlinCompilerPluginClasspath) 47} 48 49kotlin.sourceSets { 50 jvmTest.dependencies { 51 api "com.devexperts.lincheck:lincheck:$lincheck_version" 52 api "com.esotericsoftware:kryo:4.0.0" 53 implementation project (":android-unit-tests") 54 } 55} 56 57task checkJdk16() { 58 // only fail w/o JDK_16 when actually trying to compile, not during project setup phase 59 doLast { 60 if (!System.env.JDK_16) { 61 throw new GradleException("JDK_16 environment variable is not defined. " + 62 "Can't build against JDK 1.6 runtime and run JDK 1.6 compatibility tests. " + 63 "Please ensure JDK 1.6 is installed and that JDK_16 points to it.") 64 } 65 } 66} 67 68tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { 69 kotlinOptions.jdkHome = System.env.JDK_16 70 // only fail when actually trying to compile, not during project setup phase 71 dependsOn(checkJdk16) 72} 73 74jvmTest { 75 minHeapSize = '1g' 76 maxHeapSize = '1g' 77 enableAssertions = true 78 systemProperty 'java.security.manager', 'kotlinx.coroutines.TestSecurityManager' 79 exclude '**/*LFStressTest.*' 80 systemProperty 'kotlinx.coroutines.scheduler.keep.alive.sec', '100000' // any unpark problem hangs test 81} 82 83task lockFreedomTest(type: Test, dependsOn: compileTestKotlinJvm) { 84 classpath = files { jvmTest.classpath } 85 testClassesDirs = files { jvmTest.testClassesDirs } 86 include '**/*LFStressTest.*' 87 enableAssertions = true 88 testLogging.showStandardStreams = true 89} 90 91task jdk16Test(type: Test, dependsOn: [compileTestKotlinJvm, checkJdk16]) { 92 classpath = files { jvmTest.classpath } 93 testClassesDirs = files { jvmTest.testClassesDirs } 94 executable = "$System.env.JDK_16/bin/java" 95 exclude '**/*LFStressTest.*' // lock-freedom tests use LockFreedomTestEnvironment which needs JDK8 96 exclude '**/*LCStressTest.*' // lic-check tests use LinChecker which needs JDK8 97 exclude '**/exceptions/**' // exceptions tests check suppressed exception which needs JDK8 98 exclude '**/ExceptionsGuideTest.*' 99} 100 101// Run these tests only during nightly stress test 102jdk16Test.onlyIf { project.properties['stressTest'] != null } 103 104// Always run those tests 105task moreTest(dependsOn: [lockFreedomTest, jdk16Test]) 106build.dependsOn moreTest 107 108task testsJar(type: Jar, dependsOn: jvmTestClasses) { 109 classifier = 'tests' 110 from compileTestKotlinJvm.destinationDir 111} 112 113artifacts { 114 archives testsJar 115} 116