Created
March 3, 2018 21:24
-
-
Save Odepax/089a8ae73fde4b320d8ab4a5fb39e9d0 to your computer and use it in GitHub Desktop.
Gradle + Kotlin + Spek + Jacoco (March 2018)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// [ INFO ] | |
// | |
// Date: 2018-03-03 | |
// Works on: [ ? Linux ] [ Y Windows ] [ ? MacOSX ] | |
// Gradle: 4.6.0 | |
// Kotlin: 1.2.30 | |
// Spek: 1.1.5 | |
// JUnit Platform: 1.0.0 | |
// Jacoco: 0.8.0 | |
// | |
// [ SOURCES ] | |
// | |
// Kotlin: | |
// https://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions | |
// | |
// Spek: | |
// http://spekframework.org/docs/latest/#_gradle | |
// | |
// JUnit: | |
// https://github.com/junit-team/junit5-samples/blob/r5.1.0/junit5-gradle-consumer/build.gradle | |
// https://junit.org/junit5/docs/current/user-guide/#running-tests | |
// | |
// Jacoco: | |
// https://stackoverflow.com/a/34142984/6285331 | |
// https://docs.gradle.org/current/userguide/jacoco_plugin.html | |
// | |
// The Holy Grail: | |
// https://github.com/junit-team/junit5/issues/700#issuecomment-285012123 | |
// | |
buildscript { | |
ext.kotlinVersion = "1.2.30" | |
ext.junitPlatformVersion = "1.0.0" | |
ext.spekVersion = "1.1.5" | |
ext.jacocoToolVersion = "0.8.0" | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" | |
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion" | |
} | |
} | |
apply plugin: "kotlin" | |
apply plugin: "org.junit.platform.gradle.plugin" | |
apply plugin: "jacoco" | |
repositories { | |
mavenCentral() | |
maven { url "http://dl.bintray.com/jetbrains/spek" } | |
} | |
dependencies { | |
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" | |
// Spek requires fixing Kotlin Reflect version. | |
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" | |
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" | |
testCompile "org.jetbrains.spek:spek-api:$spekVersion" | |
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:$spekVersion" | |
} | |
junitPlatform { | |
filters { | |
engines { | |
include "spek" | |
} | |
} | |
} | |
jacoco { | |
toolVersion = "$jacocoToolVersion" | |
reportsDir = file("$buildDir/jacoco") // Jacoco's output root. | |
// Originally, it "listens" to the `test` task, but Spek uses `junitPlatformTest`... | |
applyTo junitPlatformTest | |
} | |
junitPlatformTest { | |
jacoco { | |
// Tells JUnit to output its test execution data here. | |
destinationFile = file("$buildDir/jacoco/junitExecutionData.exec") | |
} | |
} | |
jacocoTestReport { | |
// Tells Jacoco to get its test execution data from JUnit. | |
executionData = files("$buildDir/jacoco/junitExecutionData.exec") | |
reports { | |
csv.enabled = false | |
xml.enabled = false | |
html.enabled = true | |
html.destination file("$buildDir/jacoco/html") | |
} | |
// Tells Jacoco to work on Kotlin code coverage. | |
sourceSets sourceSets.main | |
sourceDirectories = files(sourceSets.main.allSource.srcDirs) | |
classDirectories = files(sourceSets.main.output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment