Skip to content

Commit 1b1f337

Browse files
Merge pull request #55 from mduesterhoeft/coverage-plugin
Coverage for gradle plugin
2 parents 6da60dc + 1d47d23 commit 1b1f337

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ allprojects {
5656
apply(plugin = "jacoco")
5757
apply(plugin = "maven-publish")
5858
apply(plugin = "org.jmailen.kotlinter")
59-
6059
}
6160
}
6261

6362

64-
6563
subprojects {
6664

6765
val jacksonVersion by extra { "2.9.5" }

restdocs-api-spec-gradle-plugin/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ gradlePlugin {
2626
val jacksonVersion: String by extra
2727
val junitVersion: String by extra
2828

29+
val jacocoRuntime by configurations.creating
30+
2931
dependencies {
3032
compileOnly(gradleKotlinDsl())
3133

@@ -44,4 +46,22 @@ dependencies {
4446
testImplementation("com.jayway.jsonpath:json-path:2.4.0")
4547

4648
testCompile(gradleTestKit())
49+
50+
jacocoRuntime("org.jacoco:org.jacoco.agent:0.8.2:runtime")
51+
}
52+
53+
// generate gradle properties file with jacoco agent configured
54+
// see https://discuss.gradle.org/t/testkit-jacoco-coverage/18792
55+
val createTestKitFiles by tasks.creating {
56+
val outputDir = project.file("$buildDir/testkit")
57+
58+
inputs.files(jacocoRuntime)
59+
outputs.dir(outputDir)
60+
61+
doLast {
62+
outputDir.mkdirs()
63+
file("$outputDir/testkit-gradle.properties").writeText("org.gradle.jvmargs=-javaagent:${jacocoRuntime.asPath}=destfile=$buildDir/jacoco/test.exec")
64+
}
4765
}
66+
67+
tasks["test"].dependsOn(createTestKitFiles)

restdocs-api-spec-gradle-plugin/src/test/kotlin/com/epages/restdocs/apispec/gradle/RestdocsOpenApiTaskTestBase.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ abstract class RestdocsOpenApiTaskTestBase {
4646
buildFile = resolve("build.gradle").toFile()
4747
snippetsFolder = resolve("build/generated-snippets").toFile().apply { mkdirs() }
4848
outputFolder = resolve("build/openapi").toFile()
49+
50+
initializeGradleProperties()
4951
}
5052
}
5153

@@ -245,4 +247,10 @@ abstract class RestdocsOpenApiTaskTestBase {
245247

246248
protected fun outputFileContext(): DocumentContext =
247249
JsonPath.parse(outputFolder.resolve("$outputFileNamePrefix.$format").readText().also { println(it) })
250+
251+
private fun Path.initializeGradleProperties() {
252+
// jacoco agent configuration
253+
resolve("gradle.properties").toFile()
254+
.writeText(File("build/testkit/testkit-gradle.properties").readText())
255+
}
248256
}

samples/restdocs-api-spec-sample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111
dependencies {
1212
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
13-
classpath("com.epages:restdocs-api-spec-gradle-plugin:0.0.6")
13+
classpath("com.epages:restdocs-api-spec-gradle-plugin:0.5.0")
1414
}
1515
}
1616

@@ -42,7 +42,7 @@ dependencies {
4242
testCompile('org.springframework.boot:spring-boot-starter-test')
4343
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
4444

45-
testCompile('com.epages:restdocs-api-spec:0.0.6')
45+
testCompile('com.epages:restdocs-api-spec:0.5.0')
4646
//testCompile project(':restdocs-api-spec') //enable for depending on the submodule directly
4747
testCompile('com.google.guava:guava:23.0')
4848
}

0 commit comments

Comments
 (0)