Skip to content

Instantly share code, notes, and snippets.

@yclian
Last active August 29, 2015 14:02
Show Gist options
  • Save yclian/6b157eab4e609ce16d78 to your computer and use it in GitHub Desktop.
Save yclian/6b157eab4e609ce16d78 to your computer and use it in GitHub Desktop.
Additional configuration for Gradle to publish JaCoCo report to Sonar
build.gradle | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/build.gradle b/build.gradle
index cc52b8f..c053194 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,6 +5,7 @@ apply from: "${ext.scriptDir}/common/java.gradle"
apply from: 'libraries.gradle'
apply plugin: 'application'
+apply plugin: 'jacoco'
description 'My project'
defaultTasks 'build', 'run'
@@ -44,6 +45,29 @@ dependencies {
testCompile libraries.springTest
}
+test {
+ jacoco {
+ append = false
+ destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
+ }
+}
+
+jacoco {
+ toolVersion = '0.7.1.201405082137'
+}
+
+jacocoTestReport {
+ reports {
+ xml.enabled true
+ }
+}
+
+sonarRunner {
+ sonarProperties {
+ property 'sonar.jacoco.reportPath', "$buildDir/jacoco/jacocoTest.exec"
+ }
+}
+
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
build.gradle | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/build.gradle b/build.gradle
index d391ba5..2da0e4a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,6 +13,8 @@ allprojects {
subprojects { project ->
+ apply plugin: 'jacoco'
+
configurations{
// See: http://www.sinking.in/blog/provided-scope-in-gradle/
provided
@@ -56,10 +58,32 @@ subprojects { project ->
}
test {
+
+ jacoco {
+ append = false
+ destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
+ }
+
testLogging {
events "passed", "skipped", "failed"
}
}
+
+ jacoco {
+ toolVersion = '0.7.1.201405082137'
+ }
+
+ jacocoTestReport {
+ reports {
+ xml.enabled true
+ }
+ }
+
+ sonarRunner {
+ sonarProperties {
+ property 'sonar.jacoco.reportPath', "$buildDir/jacoco/jacocoTest.exec"
+ }
+ }
}
@yclian
Copy link
Author

yclian commented Jun 2, 2014

Just added diff for multi-module projects. Yes, you have to configure the subprojects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment