【问题标题】:Compilation fails using Gradle and Kotlin使用 Gradle 和 Kotlin 编译失败
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-08-26
    • 2018-08-05
    • 2021-08-29
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多