• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
2
3/*
4 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
5 */
6
7apply from: rootProject.file("gradle/compile-jvm.gradle")
8
9repositories {
10    mavenLocal()
11    mavenCentral()
12}
13
14sourceSets {
15    npmTest {
16        kotlin
17        compileClasspath += sourceSets.test.runtimeClasspath
18        runtimeClasspath += sourceSets.test.runtimeClasspath
19    }
20    mavenTest {
21        kotlin
22        compileClasspath += sourceSets.test.runtimeClasspath
23        runtimeClasspath += sourceSets.test.runtimeClasspath
24    }
25    debugAgentTest {
26        kotlin
27        compileClasspath += sourceSets.test.runtimeClasspath
28        runtimeClasspath += sourceSets.test.runtimeClasspath
29    }
30
31    coreAgentTest {
32        kotlin
33        compileClasspath += sourceSets.test.runtimeClasspath
34        runtimeClasspath += sourceSets.test.runtimeClasspath
35    }
36}
37
38compileDebugAgentTestKotlin {
39    kotlinOptions {
40        freeCompilerArgs += ["-Xallow-kotlin-package"]
41    }
42}
43
44task npmTest(type: Test) {
45    def sourceSet = sourceSets.npmTest
46    environment "projectRoot", project.rootDir
47    environment "deployVersion", version
48    def dryRunNpm = project.properties['dryRun']
49    def doRun = dryRunNpm == "true" // so that we don't accidentally publish anything, especially before the test
50    onlyIf { doRun }
51    if (doRun) { // `onlyIf` only affects execution of the task, not the dependency subtree
52        dependsOn(project(':').getTasksByName("publishNpm", true))
53    }
54    testClassesDirs = sourceSet.output.classesDirs
55    classpath = sourceSet.runtimeClasspath
56}
57
58task mavenTest(type: Test) {
59    def sourceSet = sourceSets.mavenTest
60    dependsOn(project(':').getTasksByName("publishToMavenLocal", true))
61    testClassesDirs = sourceSet.output.classesDirs
62    classpath = sourceSet.runtimeClasspath
63    // we can't depend on the subprojects because we need to test the classfiles that are published in the end.
64    // also, we can't put this in the `dependencies` block because the resolution would happen before publication.
65    def mavenTestClasspathConfiguration = project.configurations.detachedConfiguration(
66            project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"),
67            project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"))
68
69    mavenTestClasspathConfiguration.attributes {
70        attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
71    }
72
73    classpath += mavenTestClasspathConfiguration
74}
75
76task debugAgentTest(type: Test) {
77    def sourceSet = sourceSets.debugAgentTest
78    dependsOn(project(':kotlinx-coroutines-debug').shadowJar)
79    jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-debug').shadowJar.outputs.files.getFiles()[0])
80    testClassesDirs = sourceSet.output.classesDirs
81    classpath = sourceSet.runtimeClasspath
82}
83
84task coreAgentTest(type: Test) {
85    def sourceSet = sourceSets.coreAgentTest
86    dependsOn(project(':kotlinx-coroutines-core').jvmJar)
87    jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-core').jvmJar.outputs.files.getFiles()[0])
88    testClassesDirs = sourceSet.output.classesDirs
89    classpath = sourceSet.runtimeClasspath
90}
91
92dependencies {
93    testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
94    testCompile 'junit:junit:4.12'
95    npmTestCompile 'org.apache.commons:commons-compress:1.18'
96    npmTestCompile 'com.google.code.gson:gson:2.8.5'
97    debugAgentTestCompile project(':kotlinx-coroutines-core')
98    debugAgentTestCompile project(':kotlinx-coroutines-debug')
99    coreAgentTestCompile project(':kotlinx-coroutines-core')
100}
101
102compileTestKotlin {
103    kotlinOptions.jvmTarget = "1.8"
104}
105
106check {
107    dependsOn([npmTest, mavenTest, debugAgentTest, coreAgentTest])
108}
109