【发布时间】:2017-08-11 15:28:28
【问题描述】:
我正在浏览 Kotlin in Action 书中的示例。 gradle buid脚本如下:
group 'kotlin-in-action'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.2-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.12'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "junit:junit:4.12"
compile 'junit:junit:4.12'
compile 'junit:junit:4.12'
}
sourceSets {
main.kotlin.srcDirs += 'src'
}
除了两个使用 junit 的类之外,所有脚本都可以编译。
package ch06.ex1_8_1_LateinitializedProperties
import org.junit.Before
import org.junit.Test
import org.junit.Assert
class MyService {
fun performAction(): String = "foo"
}
class MyTest {
private var myService: MyService? = null
@Before fun setUp() {
myService = MyService()
}
@Test fun testAction() {
Assert.assertEquals("foo",
myService!!.performAction())
}
}
编译器说它找不到junit。我尝试在 IntelliJ 中添加 jar 文件,但这并没有解决问题。我添加的 jar 文件是 junit 和 hamscrest-core。这都是 4.12 版本。
【问题讨论】:
-
显示你的项目结构。
标签: compilation kotlin junit4