Kotlin中的测试功能无法在主模块中找到功能

时间:2019-12-15 00:32:29

标签: gradle kotlin

我在Kotlin中使用gradle进行了标准(多)项目设置,其中有一个/ src / main / kotlin /和/ src / test / kotlin/。

我的主模块中有一个要测试的函数,但是当我在测试模块中相同名称的目录中创建测试函数时,找不到要测试的函数,该函数不可调用。

作为参考,根目录build.gradle

    ext.kotlin_version='1.3.61'
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

}

allprojects {
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'kotlin'
    version '1.0-SNAPSHOT'

    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        compileOnly 'org.projectlombok:lombok:1.18.8'
        annotationProcessor 'org.projectlombok:lombok:1.18.8'
        implementation "org.nd4j:nd4j-native-platform:1.0.0-beta5"
        implementation "org.apache.commons:commons-lang3:3.9"
        implementation "org.apache.commons:commons-math4"
        implementation "io.ktor:ktor-server-core:1.2.6"

        implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
        testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
        testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlin_version"
        testCompile group: 'junit', name: 'junit', version: '4.12'

    }

    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin/'
        test.java.srcDirs += 'src/test/kotlin/'
    }

    compileKotlin {
        kotlinOptions {
            jvmTarget = '1.8'
            apiVersion = '1.3'
            languageVersion = '1.3'
        }
    }
}

和子项目build.gradle:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin/'
    test.java.srcDirs += 'src/test/kotlin/'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.nd4j:nd4j-native-platform"
    implementation "org.apache.commons:commons-lang3"
    implementation "org.apache.commons:commons-math4"
}

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

任何帮助将不胜感激

0 个答案:

没有答案