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`.
This commit is contained in:
Sergey Igushkin
2017-02-07 16:43:48 +03:00
parent 607e205ad4
commit 292f010e59
7 changed files with 87 additions and 8 deletions
@@ -79,10 +79,10 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
@Test
fun testCompileTestCouldAccessProduction() {
val project = Project("kotlin2JsProjectWithTests", "2.10")
project.build("build") {
assertSuccessful()
assertContains(
":compileKotlin2Js",
":compileTestKotlin2Js"
@@ -93,6 +93,23 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
}
}
@Test
fun testJsCustomSourceSet() {
val project = Project("kotlin2JsProjectWithCustomSourceset", "2.10")
project.build("build") {
assertSuccessful()
assertContains(
":compileKotlin2Js",
":compileIntegrationTestKotlin2Js"
)
assertFileExists("build/kotlin2js/main/module.js")
assertFileExists("build/kotlin2js/integrationTest/module-inttests.js")
}
}
@Test
fun testKotlinJsBuiltins() {
val project = Project("kotlinBuiltins", "3.2")
@@ -0,0 +1,42 @@
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
repositories {
mavenLocal()
}
sourceSets {
integrationTest
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
compileIntegrationTestKotlin2Js.dependsOn compileKotlin2Js
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
compileIntegrationTestKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/integrationTest/module-inttests.js"
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
integrationTestCompile files(file(compileKotlin2Js.kotlinOptions.outputFile).parent)
integrationTestCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
task jarSources(type: Jar) {
from sourceSets.main.allSource
classifier = 'source'
}
artifacts {
compile jarSources
}
@@ -0,0 +1,13 @@
package test
import example.MyProductionClass
import org.junit.Test
class MainIT {
@Test
fun mySimpleTest() {
listOf(1, 2, 3).forEach { // check that stdlib is available
MyProductionClass().i = it // check that production code is available
}
}
}
@@ -0,0 +1,5 @@
package example
class MyProductionClass {
var i = 0
}
@@ -15,6 +15,7 @@ repositories {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
task jarSources(type: Jar) {
@@ -4,7 +4,7 @@ import org.junit.Test
import example.MyProductionClass
class MyTest {
@Test
@Test
fun mySimpleTest() {
MyProductionClass().i = 10
}
@@ -55,6 +55,11 @@ const val USING_EXPERIMENTAL_INCREMENTAL_MESSAGE = "Using experimental kotlin in
abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCompile(), CompilerArgumentAware {
abstract protected fun populateCompilerArguments(): T
protected val additionalClasspath = arrayListOf<File>()
protected val compileClasspath: Iterable<File>
get() = (classpath + additionalClasspath)
.filterTo(LinkedHashSet(), File::exists)
override val serializedCompilerArguments: List<String>
get() {
val arguments = populateCompilerArguments()
@@ -166,10 +171,6 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
}
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
private val additionalClasspath = arrayListOf<File>()
private val compileClasspath: Iterable<File>
get() = (classpath + additionalClasspath)
.filterTo(LinkedHashSet(), File::exists)
internal val kaptOptions = KaptOptions()
internal val pluginOptions = CompilerPluginOptions()
@@ -342,7 +343,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
?.let { if (LibraryUtils.isKotlinJavascriptLibrary(it)) it else null }
?.absolutePath
val dependencies = project.configurations.getByName("compile")
val dependencies = compileClasspath
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
.map { it.canonicalPath }