0

I have a standard LibGdx project setup by the LibGdx tool, only targeting desktop. It uses Gradle (Groovy DSL) to manage dependencies and tasks. I've converted the core module to Kotlin, and I'm trying to add a Kotlin test module using Kotest.

I've followed the Kotest instructions for Gradle on their GitHub but the compile is failing because StringSpec isn't reocgnised (Unresolved reference: StringSpec). I think LibGdx's default Gradle setup may be a little outdated or use older syntax/structure, and perhaps it's conflicting with Kotest's instructions intended for newer versions of Gradle?

For now I've removed any test and am just trying to get it to recognise StringSpec and compile. I've not even reached the stage of getting IntelliJ to recognise and run the tests. Here's what I have so far:

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 (ie the root buildfile)

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', name: 'ktx-ashley', 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', name: 'ktx-ashley', 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

I don't have much JVM experience, so I'm at a bit of a loss. Hopefully I've missed something that's obvious to someone that knows Gradle better. Any ideas?

Jansky
  • 1,455
  • 1
  • 17
  • 33
  • Open `gradle/wrapper/gradle-wrapper.properties` and look at the last line. The version number is in the zip file's name. Kotest's readme says you need at least 4.6. The default for a Libgdx project might be lower than that. You can update it just by changing the number there and rebuilding. I have mine at 5.4.1. You will need to fix some other things in other Gradle files though, because new Gradle versions often break old Groovy code. – Tenfour04 Apr 05 '20 at 13:39
  • It might just work though. IIRC, it was only the android module's gradle file that I had to fix, and it looks like you don't have an android module. – Tenfour04 Apr 05 '20 at 13:40
  • Hey mate. Added the Gradle properties file to the post. Looks like I'm already on `5.4.1` unfortunately. I think IntelliJ may have updated it for me when I first opened the project? I have a vague recollection of that. – Jansky Apr 05 '20 at 14:24

0 Answers0