spek2 gradle kotlin dsl setup

So far getting spek2 setup with kotlin and a kotlin-dsl build.gradle.kts has been a massive pain in the butt.

Here are the things you need:


spek2 is not located in jcenter or maven central. Therefore you need to specify the repository. Do this in your init.gradle.kts or build.gradle.kts

repositories {
  maven(url = "https://dl.bintray.com/spekframework/spek-dev/")
}

spek2 requires quite a lot of different dependencies.

val spekVersion = "2.0.0-alpha.2"

dependencies {
  testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") {
      exclude(group = "org.jetbrains.kotlin")
  }
  testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") {
      exclude(group = "org.junit.platform")
      exclude(group = "org.jetbrains.kotlin")
  }
  testImplementation(group = "org.junit.platform", name = "junit-platform-engine", version = "1.3.0-RC1")
}

The junit platform dependency is necessary to run the tests outside of IntelliJ. If you don’t provide it, tests will succeed in IntelliJ but fail on the command line!


You must configure the Test task

tasks {
  withType<Test> {
    useJUnitPlatform {
      includeEngines("spek2")
    }
  }
}

That’s it. you can take a look at a full working application using spek2 here