首页 > 解决方案 > 使用 gradle 6.7 我无法汇总子项目的测试报告

问题描述

我正在尝试应用 gradle 文档的“示例 4。为子项目创建单元测试报告”,请参见此处

Root project name: root
group name: root.group.name
version: 1.0.0

我的项目具有以下结构:

/A/build.gradle
/B/build.gradle
/buildSrc/src/main/groovy/root.java-conventions.gradle
/build.gradle

root.java-conventions.gradle:

plugins {
    id 'java'
}

// Disable the test report for the individual test task
test {
    reports.html.enabled = false
}

// Share the test report data to be aggregated for the whole project
configurations {
    binaryTestResultsElements {
        canBeResolved = false
        canBeConsumed = true
        attributes {
            attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
            attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'test-report-data'))
        }
        outgoing.artifact(test.binaryResultsDirectory)
    }
}

在根项目的 build.gradle 中:

plugins {
    // Apply the groovy Plugin to add support for Groovy.
    id 'groovy'

    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
}

configurations {
    testReportData {
        canBeResolved = true
        canBeConsumed = false
        attributes {
            attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
            attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'test-report-data'))
        }
    }
}

dependencies {
    testReportData project(":A")
    testReportData project(":B")
}

tasks.register('testReport', TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    // Use test results from testReportData configuration
    testResultDirs.from(configurations.testReportData)
}

我想我正确地应用了这个例子。

但是,gradle 输出以下错误:

Could not determine the dependencies of task ':testReport'.
> Could not resolve all task dependencies for configuration ':testReportData'.
> Could not resolve project :A.
        Required by:
project :
> No matching variant of project :A was found. The consumer was configured to find documentation of type 'test-report-data' but:
- Variant 'apiElements' capability root.group.name:A:1.0.0:
- Incompatible because this component declares a library and the consumer needed documentation
- Other compatible attribute:
- Doesn't say anything about the documentation type (required documentation of type 'test-report-data')
- Variant 'runtimeElements' capability root.group.name:A:1.0.0:
- Incompatible because this component declares a library and the consumer needed documentation
- Other compatible attribute:
- Doesn't say anything about the documentation type (required documentation of type 'test-report-data')
- Variant 'sourcesElements' capability root.group.name:A:1.0.0 declares documentation:
- Incompatible because this component declares sources and the consumer needed documentation of type 'test-report-data'

知道为什么这对我来说失败了吗?

标签: gradlebuild.gradle

解决方案


推荐阅读