1+ import org.gradle.api.plugins.jvm.internal.JvmPluginServices
2+ import org.gradle.kotlin.dsl.support.serviceOf
3+
14// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
25// SPDX-License-Identifier: Apache-2.0
36
@@ -21,26 +24,27 @@ val aggregateCoverage by configurations.creating {
2124 isCanBeConsumed = false
2225}
2326
24- // Resolvable configuration to resolve the classes of all dependencies
25- val classPath by configurations.creating {
27+ val aggregateCoverageReportResults by configurations.creating {
2628 isVisible = false
27- isCanBeResolved = true
28- isCanBeConsumed = false
2929 extendsFrom(aggregateCoverage)
30+ }
31+ // magic to resolve all project dependencies transitively
32+ serviceOf<JvmPluginServices >().configureAsRuntimeClasspath(aggregateCoverageReportResults)
33+
34+
35+ // view to resolve the classes of all dependencies
36+ val classPath = aggregateCoverageReportResults.incoming.artifactView {
37+ componentFilter { it is ProjectComponentIdentifier }
3038 attributes {
31- attribute(Usage .USAGE_ATTRIBUTE , objects.named(Usage .JAVA_RUNTIME ))
32- attribute(Category .CATEGORY_ATTRIBUTE , objects.named(Category .LIBRARY ))
3339 attribute(LibraryElements .LIBRARY_ELEMENTS_ATTRIBUTE , objects.named(LibraryElements .CLASSES ))
34- attribute(Bundling .BUNDLING_ATTRIBUTE , objects.named(Bundling .EXTERNAL ))
3540 }
3641}
3742
38- // A resolvable configuration to collect source code
39- val sourcesPath by configurations.creating {
40- isVisible = false
41- isCanBeResolved = true
42- isCanBeConsumed = false
43- extendsFrom(aggregateCoverage)
43+
44+ // view to collect source code
45+ val sourcesPath = aggregateCoverageReportResults.incoming.artifactView {
46+ withVariantReselection()
47+ componentFilter { it is ProjectComponentIdentifier }
4448 attributes {
4549 attribute(Category .CATEGORY_ATTRIBUTE , objects.named(Category .VERIFICATION ))
4650 attribute(Bundling .BUNDLING_ATTRIBUTE , objects.named(Bundling .EXTERNAL ))
@@ -49,29 +53,27 @@ val sourcesPath by configurations.creating {
4953}
5054
5155// A resolvable configuration to collect JaCoCo coverage data
52- val coverageDataPath by configurations.creating {
53- isVisible = false
54- isCanBeResolved = true
55- isCanBeConsumed = false
56- extendsFrom(aggregateCoverage)
56+ val coverageDataPath = aggregateCoverageReportResults.incoming.artifactView {
57+ withVariantReselection()
58+ componentFilter { it is ProjectComponentIdentifier }
5759 attributes {
58- attribute(Category .CATEGORY_ATTRIBUTE , objects.named(Category .DOCUMENTATION ))
59- attribute(DocsType . DOCS_TYPE_ATTRIBUTE , objects.named(" jacoco-coverage-data " ))
60- attribute(Usage . USAGE_ATTRIBUTE , objects.named( Usage . JAVA_RUNTIME ) )
60+ attribute(Category .CATEGORY_ATTRIBUTE , objects.named(Category .VERIFICATION ))
61+ attribute(VerificationType . VERIFICATION_TYPE_ATTRIBUTE , objects.named(VerificationType . JACOCO_RESULTS ))
62+ attribute(ArtifactTypeDefinition . ARTIFACT_TYPE_ATTRIBUTE , ArtifactTypeDefinition . BINARY_DATA_TYPE )
6163 }
6264}
6365
6466// Register a code coverage report task to generate the aggregated report
6567tasks.register<JacocoReport >(" coverageReport" ) {
6668 additionalClassDirs(
67- classPath.filter { it.isDirectory }.asFileTree.matching {
69+ classPath.files. filter { it.isDirectory }.asFileTree.matching {
6870 include(" **/software/aws/toolkits/**" )
6971 exclude(" **/software/aws/toolkits/telemetry/**" )
7072 }
7173 )
7274
73- additionalSourceDirs(sourcesPath.incoming.artifactView { lenient( true ) }. files)
74- executionData(coverageDataPath.incoming.artifactView { lenient( true ) }. files.filter { it.exists() && it.extension == " exec " } )
75+ additionalSourceDirs(sourcesPath.files)
76+ executionData(coverageDataPath.files)
7577
7678 reports {
7779 html.required.set(true )
0 commit comments