使用Gradle和Kotlin编译失败

我正在阅读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。

我已经解决了这个问题 我不得不从mavan保存库中添加Junit和hamcrest-core jar文件。

Interesting Posts