Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
| 5 | apply plugin: 'kotlin-multiplatform' |
| 6 | apply from: rootProject.file("gradle/targets.gradle") |
| 7 | apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle") |
| 8 | apply from: rootProject.file("gradle/compile-common.gradle") |
| 9 | apply from: rootProject.file("gradle/compile-js-multiplatform.gradle") |
| 10 | apply from: rootProject.file("gradle/compile-native-multiplatform.gradle") |
| 11 | apply 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 | */ |
| 17 | kotlin { |
| 18 | configure(sourceSets) { |
| 19 | def srcDir = name.endsWith('Main') ? 'src' : 'test' |
| 20 | def platform = name[0..-5] |
| 21 | kotlin.srcDir "$platform/$srcDir" |
Vsevolod Tolstopyatov | 8273a75 | 2019-03-15 19:24:41 +0300 | [diff] [blame] | 22 | if (name == "jvmMain") { |
| 23 | resources.srcDirs = ["$platform/resources"] |
| 24 | } else if (name == "jvmTest") { |
| 25 | resources.srcDirs = ["$platform/test-resources"] |
| 26 | } |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 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 | |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 45 | configurations { |
| 46 | configureKotlinJvmPlatform(kotlinCompilerPluginClasspath) |
| 47 | } |
| 48 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 49 | kotlin.sourceSets { |
| 50 | jvmTest.dependencies { |
| 51 | api "com.devexperts.lincheck:lincheck:$lincheck_version" |
| 52 | api "com.esotericsoftware:kryo:4.0.0" |
sokolova | 15b6345 | 2019-01-28 11:43:44 +0300 | [diff] [blame] | 53 | implementation project (":android-unit-tests") |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | task 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 | |
| 68 | tasks.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 | |
| 74 | jvmTest { |
| 75 | minHeapSize = '1g' |
| 76 | maxHeapSize = '1g' |
| 77 | enableAssertions = true |
| 78 | systemProperty 'java.security.manager', 'kotlinx.coroutines.TestSecurityManager' |
Roman Elizarov | 7672c52 | 2019-08-28 12:04:59 +0300 | [diff] [blame] | 79 | exclude '**/*LFStressTest.*' |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 80 | systemProperty 'kotlinx.coroutines.scheduler.keep.alive.sec', '100000' // any unpark problem hangs test |
| 81 | } |
| 82 | |
| 83 | task lockFreedomTest(type: Test, dependsOn: compileTestKotlinJvm) { |
| 84 | classpath = files { jvmTest.classpath } |
| 85 | testClassesDirs = files { jvmTest.testClassesDirs } |
Roman Elizarov | 7672c52 | 2019-08-28 12:04:59 +0300 | [diff] [blame] | 86 | include '**/*LFStressTest.*' |
Roman Elizarov | 0b16abf | 2019-09-03 11:07:11 +0300 | [diff] [blame] | 87 | enableAssertions = true |
| 88 | testLogging.showStandardStreams = true |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | task jdk16Test(type: Test, dependsOn: [compileTestKotlinJvm, checkJdk16]) { |
| 92 | classpath = files { jvmTest.classpath } |
| 93 | testClassesDirs = files { jvmTest.testClassesDirs } |
| 94 | executable = "$System.env.JDK_16/bin/java" |
Roman Elizarov | 7672c52 | 2019-08-28 12:04:59 +0300 | [diff] [blame] | 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 |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 98 | exclude '**/ExceptionsGuideTest.*' |
| 99 | } |
| 100 | |
| 101 | // Run these tests only during nightly stress test |
| 102 | jdk16Test.onlyIf { project.properties['stressTest'] != null } |
| 103 | |
| 104 | // Always run those tests |
| 105 | task moreTest(dependsOn: [lockFreedomTest, jdk16Test]) |
| 106 | build.dependsOn moreTest |
| 107 | |
| 108 | task testsJar(type: Jar, dependsOn: jvmTestClasses) { |
| 109 | classifier = 'tests' |
| 110 | from compileTestKotlinJvm.destinationDir |
| 111 | } |
| 112 | |
| 113 | artifacts { |
| 114 | archives testsJar |
| 115 | } |