簡體   English   中英

當我在 gradle 中添加新的源集時“未配置 Kotlin”。 (IntelliJ)

[英]"Kotlin not configured" when I add a new source set in gradle. (IntelliJ)

我有這個 gradle 項目,我添加了兩個新的源集“acceptanceTest”和“integrationTest”。 我首先添加了“acceptanceTest”並且它正常工作,然后我復制了代碼以創建“integrationTest”。

當我在 integrationTest 下創建文件時,我在 IntelliJ 中得到“Kotlin 未配置”。 當我嘗試運行 gradle 時也是如此。

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.71'
}

apply plugin: 'idea'

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    jcenter()
}

configurations {
    acceptanceTestCompile.extendsFrom testCompile
    acceptanceTestRuntime.extendsFrom testRuntime

    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
}

sourceSets {
    acceptanceTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file("src/acceptanceTest/kotlin")
        }
        resources.srcDir file("src/acceptanceTest/resources")
    }

    kotlin {

    }
    integrationTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file("src/integrationTest/kotlin")
        }
        resources.srcDir file("src/integrationTest/resources")
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "org.yaml:snakeyaml:1.26"

    testImplementation "org.junit.jupiter:junit-jupiter:5.6.1"
    testImplementation "io.mockk:mockk:1.9.3.kotlin12"
    testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    testImplementation "org.assertj:assertj-core:3.11.1"

    acceptanceTestRuntime "org.yaml:snakeyaml:1.26"
    acceptanceTestImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek_version"
    acceptanceTestImplementation "org.spekframework.spek2:spek-runner-junit5:$spek_version"
    acceptanceTestImplementation "org.assertj:assertj-core:3.11.1"
    acceptanceTestImplementation "io.mockk:mockk:1.9.3.kotlin12"

}


task acceptanceTest(type: Test) {
    testClassesDirs = sourceSets.acceptanceTest.output.classesDirs
    classpath = sourceSets.acceptanceTest.runtimeClasspath
    outputs.upToDateWhen { false }
}
task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }
}

check.dependsOn integrationTest
integrationTest.mustRunAfter test

check.dependsOn acceptanceTest
acceptanceTest.mustRunAfter integrationTest

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}
acceptanceTest {
    useJUnitPlatform {
        includeEngines 'spek2'
    }
    testLogging {
        events("passed", "skipped", "failed")
    }
}
integrationTest {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

idea {
    module {
        testSourceDirs += project.sourceSets.integrationTest.kotlin.srcDirs
        testSourceDirs += project.sourceSets.integrationTest.resources.srcDirs
        testSourceDirs += project.sourceSets.acceptanceTest.kotlin.srcDirs
        testSourceDirs += project.sourceSets.acceptanceTest.resources.srcDirs
    }
}

我現在找到了答案。 在依賴項中,您需要為該源集添加 kotlin stdlib。 像 integrationTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM