2017-08-11 72 views
0

我正在阅读Kotlin in Action书中的示例。该gradle这个剧本打造专业化为:使用Gradle和Kotlin编译失败

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。

+0

显示您的项目结构。 –

回答

0

我解决了这个问题。我必须添加mavan存储库中的Junit和hamcrest-core jar文件。