From 4d9bd6f216c7d6bde919e6f6a588b4658f08e6fa Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 12 Mar 2015 18:11:46 +0100 Subject: [PATCH] Add jacocoRootReport task to build.gradle with the correct parameters to collect the jacocoReports from all subprojects and put the jacocoTestReport.xml in the right place, so that the coveralls plugin is able to find it. --- .travis.yml | 2 +- build.gradle | 73 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1622438ab..24fcf017b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ install: gradle assemble script: gradle check after_success: -- gradle jacocoTestReport coveralls +- gradle jacocoRootReport coveralls diff --git a/build.gradle b/build.gradle index d41ced48a..4528a709a 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ apply from: 'version.gradle' allprojects { apply plugin: 'java' apply plugin: 'eclipse' + apply plugin: 'jacoco' ext { gitCommit = getGitCommit() @@ -35,6 +36,23 @@ allprojects { // build, causing unnecessary rebuilds. builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date()) oneLineDesc = 'An Open Source XMPP (Jabber) client library' + // A dirty hack used for Gradle's jacoco plugin, since is not + // hable to handle the case when a (sub)project has no unit + // tests. :-( + projectsWithoutUnitTests = [ + ':smack-android', + ':smack-android-extensions', + ':smack-bosh', + ':smack-compression-jzlib', + ':smack-debug', + ':smack-debug-slf4j', + ':smack-java7', + ':smack-jingle-old', + ':smack-resolver-dnsjava', + ':smack-resolver-javax', + ':smack-resolver-minidns', + ].collect{ project(it) } + projectsWithUnitTests = subprojects - projectsWithoutUnitTests androidProjects = [ ':smack-tcp', ':smack-bosh', @@ -79,6 +97,8 @@ allprojects { } repositories { + mavenLocal() + mavenCentral() // Add OSS Sonatype Snapshot repository maven { url 'https://oss.sonatype.org/content/repositories/snapshots' @@ -97,6 +117,19 @@ allprojects { options.addStringOption('Xdoclint:none', '-quiet') } } + + jacoco { + toolVersion = "0.7.4.201502262128" + } + + jacocoTestReport { + dependsOn test + sourceDirectories = project.files(sourceSets.main.allSource.srcDirs) + classDirectories = project.files(sourceSets.main.output) + reports { + xml.enabled true + } + } } gradle.taskGraph.whenReady { taskGraph -> @@ -182,17 +215,11 @@ subprojects { apply plugin: 'osgi' apply plugin: 'signing' apply plugin: 'checkstyle' - apply plugin: 'jacoco' apply plugin: 'org.kordamp.gradle.clirr' - apply plugin: "com.github.kt3k.coveralls" checkstyle { configFile = new File(rootConfigDir, 'checkstyle.xml') } - repositories { - mavenLocal() - mavenCentral() - } task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource @@ -289,19 +316,6 @@ subprojects { baseline = [group, name, clirrBaseline].join(':') failOnErrors clirrFailOnErrors } - - jacoco { - toolVersion = "0.7.1.201405082137" - } - - jacocoTestReport { - dependsOn test - sourceDirectories = project.files(sourceSets.main.allSource.srcDirs) - classDirectories = project.files(sourceSets.main.output) - reports { - xml.enabled true - } - } } subprojects*.jar { @@ -310,6 +324,27 @@ subprojects*.jar { } } +apply plugin: "com.github.kt3k.coveralls" +coveralls { + sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath +} + +task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { + dependsOn = projectsWithUnitTests.jacocoTestReport + sourceDirectories = files(projectsWithUnitTests.sourceSets.main.allSource.srcDirs) + classDirectories = files(projectsWithUnitTests.sourceSets.main.output) + executionData = files(projectsWithUnitTests.jacocoTestReport.executionData) + reports { + xml.enabled true + xml.destination ="${buildDir}/reports/jacoco/test/jacocoTestReport.xml" + } + // We could remove the following setOnlyIf line, but then + // jacocoRootReport would silently be SKIPPED if something with + // the projectsWithUnitTests is wrong (e.g. a project is missing + // in there). + setOnlyIf { true } +} + // Important to specify this task after the subprojects block task clirrRootReport(type: org.kordamp.gradle.clirr.ClirrReportTask) { dependsOn = subprojects.tasks.clirr