Skip to content

Commit 292f010

Browse files
committed
Fixed Kotlin2JsCompile not picking dependencies from configurations other than compile.
Example: apply plugin: 'kotlin2js' dependencies { ... testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" } Here, the `:compileTestKotlin2Js` task did not pick the dependency and used the `compile` classpath. This has been fixed. Also, fixed `testCompileTestCouldAccessProduction` and added `testJsCustomSourceSet`.
1 parent 607e205 commit 292f010

File tree

7 files changed

+87
-8
lines changed

7 files changed

+87
-8
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
7979
@Test
8080
fun testCompileTestCouldAccessProduction() {
8181
val project = Project("kotlin2JsProjectWithTests", "2.10")
82-
82+
8383
project.build("build") {
8484
assertSuccessful()
85-
85+
8686
assertContains(
8787
":compileKotlin2Js",
8888
":compileTestKotlin2Js"
@@ -93,6 +93,23 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
9393
}
9494
}
9595

96+
@Test
97+
fun testJsCustomSourceSet() {
98+
val project = Project("kotlin2JsProjectWithCustomSourceset", "2.10")
99+
100+
project.build("build") {
101+
assertSuccessful()
102+
103+
assertContains(
104+
":compileKotlin2Js",
105+
":compileIntegrationTestKotlin2Js"
106+
)
107+
108+
assertFileExists("build/kotlin2js/main/module.js")
109+
assertFileExists("build/kotlin2js/integrationTest/module-inttests.js")
110+
}
111+
}
112+
96113
@Test
97114
fun testKotlinJsBuiltins() {
98115
val project = Project("kotlinBuiltins", "3.2")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
}
5+
dependencies {
6+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
7+
}
8+
}
9+
10+
apply plugin: 'kotlin2js'
11+
12+
repositories {
13+
mavenLocal()
14+
}
15+
16+
sourceSets {
17+
integrationTest
18+
}
19+
20+
task integrationTest(type: Test) {
21+
testClassesDir = sourceSets.integrationTest.output.classesDir
22+
classpath = sourceSets.integrationTest.runtimeClasspath
23+
}
24+
25+
compileIntegrationTestKotlin2Js.dependsOn compileKotlin2Js
26+
27+
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
28+
compileIntegrationTestKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/integrationTest/module-inttests.js"
29+
30+
dependencies {
31+
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
32+
integrationTestCompile files(file(compileKotlin2Js.kotlinOptions.outputFile).parent)
33+
integrationTestCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
34+
}
35+
36+
task jarSources(type: Jar) {
37+
from sourceSets.main.allSource
38+
classifier = 'source'
39+
}
40+
artifacts {
41+
compile jarSources
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test
2+
3+
import example.MyProductionClass
4+
import org.junit.Test
5+
6+
class MainIT {
7+
@Test
8+
fun mySimpleTest() {
9+
listOf(1, 2, 3).forEach { // check that stdlib is available
10+
MyProductionClass().i = it // check that production code is available
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
class MyProductionClass {
4+
var i = 0
5+
}

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin2JsProjectWithTests/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ repositories {
1515

1616
dependencies {
1717
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
18+
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
1819
}
1920

2021
task jarSources(type: Jar) {

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlin2JsProjectWithTests/src/test/kotlin/MainTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.junit.Test
44
import example.MyProductionClass
55

66
class MyTest {
7-
@Test
7+
@Test
88
fun mySimpleTest() {
99
MyProductionClass().i = 10
1010
}

libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const val USING_EXPERIMENTAL_INCREMENTAL_MESSAGE = "Using experimental kotlin in
5555
abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCompile(), CompilerArgumentAware {
5656
abstract protected fun populateCompilerArguments(): T
5757

58+
protected val additionalClasspath = arrayListOf<File>()
59+
protected val compileClasspath: Iterable<File>
60+
get() = (classpath + additionalClasspath)
61+
.filterTo(LinkedHashSet(), File::exists)
62+
5863
override val serializedCompilerArguments: List<String>
5964
get() {
6065
val arguments = populateCompilerArguments()
@@ -166,10 +171,6 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
166171
}
167172

168173
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
169-
private val additionalClasspath = arrayListOf<File>()
170-
private val compileClasspath: Iterable<File>
171-
get() = (classpath + additionalClasspath)
172-
.filterTo(LinkedHashSet(), File::exists)
173174

174175
internal val kaptOptions = KaptOptions()
175176
internal val pluginOptions = CompilerPluginOptions()
@@ -342,7 +343,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
342343
?.let { if (LibraryUtils.isKotlinJavascriptLibrary(it)) it else null }
343344
?.absolutePath
344345

345-
val dependencies = project.configurations.getByName("compile")
346+
val dependencies = compileClasspath
346347
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
347348
.map { it.canonicalPath }
348349

0 commit comments

Comments
 (0)