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} 22 23// Use JDK 21 for this module, via a toolchain. We need JDK 21 since this module 24// depends on jdk-recent-unit-tests. 25// We must null out sourceCompatibility and targetCompatibility to use toolchains. 26java.sourceCompatibility = null 27java.targetCompatibility = null 28java.toolchain.languageVersion.set JavaLanguageVersion.of(21) 29 30// A resolvable configuration to collect source code 31def sourcesPath = configurations.create("sourcesPath") { 32 visible = false 33 canBeResolved = true 34 canBeConsumed = false 35 extendsFrom(configurations.implementation) 36 attributes { 37 attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) 38 attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) 39 attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders')) 40 } 41} 42 43// A resolvable configuration to collect JaCoCo coverage data 44def coverageDataPath = configurations.create("coverageDataPath") { 45 visible = false 46 canBeResolved = true 47 canBeConsumed = false 48 extendsFrom(configurations.implementation) 49 attributes { 50 attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) 51 attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) 52 attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data')) 53 } 54} 55 56// Task to gather code coverage from multiple subprojects 57def codeCoverageReport = tasks.register('codeCoverageReport', JacocoReport) { 58 additionalClassDirs(configurations.runtimeClasspath.filter{it.path.contains(rootProject.name) }) 59 additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) 60 executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) 61 62 reports { 63 // xml is usually used to integrate code coverage with 64 // other tools like SonarQube, Coveralls or Codecov 65 xml.required = true 66 67 // HTML reports can be used to see code coverage 68 // without any external tools 69 html.required = true 70 } 71} 72 73// These dependencies indicate which projects have tests or tested code we want to include 74// when computing overall coverage. We aim to measure coverage for all code that actually ships 75// in a Maven artifact (so, e.g., we do not measure coverage for the jmh module) 76dependencies { 77 implementation project(':annotations') 78 implementation project(':nullaway') 79 implementation project(':jar-infer:jar-infer-lib') 80 implementation project(':jar-infer:nullaway-integration-test') 81 implementation project(':guava-recent-unit-tests') 82 implementation project(':jdk-recent-unit-tests') 83} 84