Skip to content

Instantly share code, notes, and snippets.

@aalmiray
Last active October 31, 2019 19:39
Show Gist options
  • Save aalmiray/3e0e70cba66effdb449a to your computer and use it in GitHub Desktop.
Save aalmiray/3e0e70cba66effdb449a to your computer and use it in GitHub Desktop.
Gradle Glam: jacoco + coveralls
language: java
script: ./gradlew build jacocoTestReport
jdk: oraclejdk7
env:
matrix:
- TERM=dumb
after_success:
- ./gradlew jacocoRootReport coveralls
package sample;
import org.junit.Ignore;
import org.junit.Test;
import static junit.framework.Assert.fail;
public class BarTest {
@Ignore @Test
public void bar() {
fail("Not yet implemented!");
}
}
allprojects {
apply plugin: 'base'
apply plugin: 'jacoco'
repositories {
jcenter()
}
jacoco {
toolVersion = '0.7.1.201405082137'
}
}
subprojects {
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
}
jacocoTestReport {
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:1.0.2'
}
}
apply plugin: 'com.github.kt3k.coveralls'
allprojects {
apply plugin: 'base'
apply plugin: 'jacoco'
repositories {
jcenter()
}
jacoco {
toolVersion = '0.7.1.201405082137'
}
}
subprojects {
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
}
jacocoTestReport {
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
coveralls {
sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
xml.destination = "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
}
}
.
├── build.gradle
├── one
│ └── src
│ ├── main
│ │ └── java
│ │ └── sample
│ │ └── Foo.java
│ └── test
│ └── java
│ └── sample
│ └── FooTest.java
├── settings.gradle
└── two
└── src
├── main
│ └── java
│ └── sample
│ └── Bar.java
└── test
└── java
└── sample
└── BarTest.java
$ gradle clean jacocoRootReport
:clean UP-TO-DATE
:one:clean UP-TO-DATE
:two:clean UP-TO-DATE
:one:compileJava
:one:processResources UP-TO-DATE
:one:classes
:one:compileTestJava
:one:processTestResources UP-TO-DATE
:one:testClasses
:one:test
:two:compileJava
:two:processResources UP-TO-DATE
:two:classes
:two:compileTestJava
:two:processTestResources UP-TO-DATE
:two:testClasses
:two:test
:jacocoRootReport
@igordeoliveirasa
Copy link

Hi, could you help me?

I'm receiving this error:

No source file found on the project: "app"
With coverage file: /home/travis/build/igordeoliveirasa/mvt-android/app/build/reports/jacoco/test/jacocoTestReport.xml

Full Stack

18.53s$ ./gradlew jacocoRootReport coveralls
:app:jacocoRootReport
:app:coveralls
service name: travis-ci
service job id: 43264142
repo token: null
No source file found on the project: "app"
With coverage file: /home/travis/build/igordeoliveirasa/mvt-android/app/build/reports/jacoco/test/jacocoTestReport.xml

@ChristopherZhong
Copy link

The subprojects.sourceSets.main.output includes classes from the resources directory as well. So if you have third-party jar files in there, the report will include these classes. But since you did not include the sources for them, it fails. Below is what I think should be the correct line.

classDirectories =  files(subprojects.sourceSets.main.output.classesDir)

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