如何在LibGdx项目中使用Gradle配置KoTest?由于无法识别StringSpec,目前无法构建

我有一个由LibGdx工具设置的标准LibGdx项目,仅针对台式机。它使用Gradle(Groovy DSL)管理依赖关系和任务。我已经将核心模块转换为Kotlin,并且尝试使用Kotest添加Kotlin测试模块。

我在其GitHub上遵循了Gradle的Kotest指令,但编译失败,因为未识别StringSpecUnresolved reference: StringSpec)。我认为LibGdx的默认Gradle设置可能有点过时或使用了较旧的语法/结构,并且可能与Kotest针对较新版本的Gradle的说明相冲突?

目前,我已经删除了所有测试,而只是试图使其能够识别StringSpec并进行编译。我什至还没有达到让IntelliJ识别并运行测试的阶段。这是我到目前为止的内容:

core.tests / tests / com / me / game / acceptanceTests.kt

package com.jansky.myproject

class acceptanceTests : StringSpec() {

}

core.tests / gradle.build

version '1.0'

sourceCompatibility = 1.7
[compileJava,compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "tests/" ]

tasks.withType(Test) {
    useJUnitPlatform()
}

eclipse.project.name = appName + "-core.tests"

./ build.gradle(即根构建文件)

buildscript {
    ext.kotlinVersion = '1.3.71'

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
        google()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    apply plugin: "eclipse"

    version = '1.0'
    ext {
        appName = "game"
        gdxVersion = '1.9.10'
        roboVMVersion = '2.3.8'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "kotlin"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.ashley:ashley:1.7.3"
        compile group: 'io.github.libktx',name: 'ktx-ashley',version: '1.9.10-b4'
    }
}

project(":core") {
    apply plugin: "kotlin"

    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
        compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
        compile "com.badlogicgames.ashley:ashley:1.7.3"
        compile group: 'io.github.libktx',version: '1.9.10-b4'
    }
}

project(":core.tests") {
    apply plugin: "kotlin"

    test {
        useJUnitPlatform()
    }

    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
        compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
        compile "com.badlogicgames.ashley:ashley:1.7.3"
        compile group: 'io.github.libktx',version: '1.9.10-b4'
        implementation 'io.kotest:kotest-runner-junit5:4.0.2'
        implementation 'io.kotest:kotest-assertions-core:4.0.2'
    }
}

settings.gradle

include 'desktop','core','core.tests'

Gradle-wrapper.properties

#Sat Apr 04 15:53:20 BST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

我没有太多的JVM经验,所以我有点茫然。希望我错过了一些对Gradle更了解的人所显而易见的东西。有什么想法吗?

qzrobinh 回答:如何在LibGdx项目中使用Gradle配置KoTest?由于无法识别StringSpec,目前无法构建

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2509272.html

大家都在问