gradle - 当我在gradle中添加新的源集时“Kotlin not configured”。 (IntelliJ)

标签 gradle kotlin intellij-idea

我有这个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”

关于gradle - 当我在gradle中添加新的源集时“Kotlin not configured”。 (IntelliJ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60946384/

相关文章:

android - JNCryptor - RNCryptor 图像文件加密/解密

java - 如何在android中使用bitcoinj(walletappkit)从助记词创建比特币钱包

intellij-idea - 如何在 IntelliJ IDEA 中使用制表符进行缩进?

java - 类 "android.support.v4.view.ViewPager"无法实例化

node.js - npm缺少脚本:检查

gradle - 如何使用不同 gradle 多项目的子项目

java - maven和gradle可以和本地仓库共享同一个文件夹吗?

android - RxJava 2 模拟 Observable 不起作用

java - 编译错误 - 在 IntelliJ IDEA 中复制类

intellij-idea - 高效的 map 和过滤器组合与标准库