• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021. Uber Technologies
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Mostly taken from official Gradle sample: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html
18plugins {
19    id 'java'
20    id 'jacoco'
21    id 'com.github.kt3k.coveralls'
22}
23
24// A resolvable configuration to collect source code
25def sourcesPath = configurations.create("sourcesPath") {
26    visible = false
27    canBeResolved = true
28    canBeConsumed = false
29    extendsFrom(configurations.implementation)
30    attributes {
31        attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
32        attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
33        attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders'))
34    }
35}
36
37// A resolvable configuration to collect JaCoCo coverage data
38def coverageDataPath = configurations.create("coverageDataPath") {
39    visible = false
40    canBeResolved = true
41    canBeConsumed = false
42    extendsFrom(configurations.implementation)
43    attributes {
44        attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
45        attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
46        attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data'))
47    }
48}
49
50// Task to gather code coverage from multiple subprojects
51def codeCoverageReport = tasks.register('codeCoverageReport', JacocoReport) {
52    additionalClassDirs(configurations.runtimeClasspath.filter{it.path.contains(rootProject.name)  })
53    additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files)
54    executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() })
55
56    reports {
57        // xml is usually used to integrate code coverage with
58        // other tools like SonarQube, Coveralls or Codecov
59        xml.required = true
60
61        // HTML reports can be used to see code coverage
62        // without any external tools
63        html.required = true
64    }
65}
66
67coveralls {
68    jacocoReportPath = "build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
69    afterEvaluate {
70        sourceDirs = sourcesPath.incoming.artifactView { lenient(true) }.files as List<String>
71    }
72}
73
74def coverallsTask = tasks.named('coveralls')
75
76coverallsTask.configure {
77    dependsOn 'codeCoverageReport'
78}
79
80// These dependencies indicate which projects have tests or tested code we want to include
81// when computing overall coverage.  We aim to measure coverage for all code that actually ships
82// in a Maven artifact (so, e.g., we do not measure coverage for the jmh module)
83dependencies {
84    implementation project(':nullaway')
85    implementation project(':jar-infer:jar-infer-lib')
86    implementation project(':jar-infer:nullaway-integration-test')
87    implementation project(':jdk17-unit-tests')
88}
89