2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gradleのマルチプロジェクトのテスト結果とカバレッジをそれぞれ1つにまとめる

Last updated at Posted at 2017-10-10

ルートのプロジェクトのbuild.gradleを以下のように変更する

allprojects {
    apply plugin: 'java'
    apply plugin: 'jacoco'

    repositories {
        jcenter()
    }

    jacoco {
        toolVersion = '0.7.9'
    }
}

subprojects {
    test {
        reports.html.enabled = false
    }

    jacocoTestReport {
        additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
        sourceDirectories = files(sourceSets.main.allSource.srcDirs)
        classDirectories =  files(sourceSets.main.output)
        reports {
            html.enabled = true
            xml.enabled = true
            csv.enabled = false
        }
    }
}

task testRootReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    reportOn subprojects.tasks.test
}

task jacocoRootReport(type: JacocoReport) {
    dependsOn = subprojects.test
    additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
    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
    }
}

task report(dependsOn: ['testRootReport', 'jacocoRootReport'])

コマンド

./gradlew test report

結果

.
└── build
    └── reports
        ├── allTests
        │   └── index.html etc...
        └── jacoco
            └── jacocoRootReport
                └── html
                    └── index.html etc...

参考

https://gist.github.com/aalmiray/e6f54aa4b3803be0bcac
http://clash-m45.hatenablog.com/entry/2015/01/24/162621

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?