diff options
Diffstat (limited to 'buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle')
-rw-r--r-- | buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle b/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle new file mode 100644 index 0000000..1c7c97c --- /dev/null +++ b/buildSrc/src/main/groovy/nullaway.jacoco-conventions.gradle @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Mostly taken from official Gradle sample: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html +plugins { + id 'jacoco' +} + +jacoco { + toolVersion = "0.8.7" +} + +// Do not generate reports for individual projects +tasks.named("jacocoTestReport") { + enabled = false +} + +// Share sources folder with other projects for aggregated JaCoCo reports +configurations.create('transitiveSourcesElements') { + visible = false + canBeResolved = false + canBeConsumed = true + extendsFrom(configurations.implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'source-folders')) + } + sourceSets.main.java.srcDirs.forEach { + outgoing.artifact(it) + } +} + +// Share the coverage data to be aggregated for the whole product +configurations.create('coverageDataElements') { + visible = false + canBeResolved = false + canBeConsumed = true + extendsFrom(configurations.implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'jacoco-coverage-data')) + } + // This will cause the test task to run if the coverage data is requested by the aggregation task + outgoing.artifact(tasks.named("test").map { task -> + task.extensions.getByType(JacocoTaskExtension).destinationFile + }) +} |