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 'jacoco' 20} 21 22jacoco { 23 toolVersion = "0.8.7" 24} 25 26// Do not generate reports for individual projects 27tasks.named("jacocoTestReport") { 28 enabled = false 29} 30 31// Share sources folder with other projects for aggregated JaCoCo reports 32configurations.create('transitiveSourcesElements') { 33 visible = false 34 canBeResolved = false 35 canBeConsumed = true 36 extendsFrom(configurations.implementation) 37 attributes { 38 attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) 39 attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) 40 attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders')) 41 } 42 sourceSets.main.java.srcDirs.forEach { 43 outgoing.artifact(it) 44 } 45} 46 47// Share the coverage data to be aggregated for the whole product 48configurations.create('coverageDataElements') { 49 visible = false 50 canBeResolved = false 51 canBeConsumed = true 52 extendsFrom(configurations.implementation) 53 attributes { 54 attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) 55 attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) 56 attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data')) 57 } 58 // This will cause the test task to run if the coverage data is requested by the aggregation task 59 outgoing.artifact(tasks.named("test").map { task -> 60 task.extensions.getByType(JacocoTaskExtension).destinationFile 61 }) 62} 63