Last active
October 31, 2019 19:39
-
-
Save aalmiray/3e0e70cba66effdb449a to your computer and use it in GitHub Desktop.
Gradle Glam: jacoco + coveralls
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
language: java | |
script: ./gradlew build jacocoTestReport | |
jdk: oraclejdk7 | |
env: | |
matrix: | |
- TERM=dumb | |
after_success: | |
- ./gradlew jacocoRootReport coveralls |
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
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!"); | |
} | |
} |
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
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 | |
} | |
} |
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
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:1.0.2' | |
} | |
} | |
apply plugin: 'com.github.kt3k.coveralls' |
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
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" | |
} | |
} |
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
. | |
├── 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 |
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
$ 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 |
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
Hi, could you help me?
I'm receiving this error:
Full Stack