You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Android项目Allure聚合测试报告配置错误求助

解决多模块Android项目Allure聚合报告配置错误问题

错误原因分析

你遇到的问题核心是:根模块的allureGenerateCategories任务需要子模块提供带有io.qameta.allure=COPY_CATEGORIES属性的可消费配置,但子模块要么未暴露该属性,要么存在多构建变体(如dev/prod/qa的Debug/Release)导致无法自动选择匹配的变体。

具体解决步骤

1. 统一所有子模块的Allure配置

每个库模块(包括app模块)的构建脚本中,除了应用插件,还要添加属性配置并过滤不必要的变体:

Kotlin DSL (build.gradle.kts)

plugins {
    id("com.android.library") // app模块用com.android.application
    id("io.qameta.allure-adapter")
}

allure {
    autoconfigure = true // 自动配置测试结果目录
}

android {
    // 过滤变体,只保留用于生成测试报告的变体(比如Debug)
    variantFilter {
        setIgnore(buildType.name != "debug")
    }
}

// 为所有可消费配置添加Allure识别属性
configurations.all {
    if (isCanBeConsumed) {
        attributes.attribute(Attribute.of("io.qameta.allure", String::class.java), "COPY_CATEGORIES")
    }
}

Groovy DSL (build.gradle)

plugins {
    id 'com.android.library' // app模块用com.android.application
    id 'io.qameta.allure-adapter'
}

allure {
    autoconfigure = true
}

android {
    variantFilter { variant ->
        variant.setIgnore(variant.buildType.name != 'debug')
    }
}

configurations.all {
    if (canBeConsumed) {
        attributes.attribute(Attribute.of('io.qameta.allure', String), 'COPY_CATEGORIES')
    }
}

2. 根模块明确指定聚合变体

在根模块的构建脚本中,配置allureAggregate任务,指定要聚合的变体和子模块,避免多变体冲突:

Kotlin DSL (build.gradle.kts)

plugins {
    id("io.qameta.allure-aggregate-report")
}

allureAggregate {
    variants = listOf("debug") // 指定要聚合的变体
    projects = listOf(":core", ":feature", ":onscene", ":app") // 列出所有要聚合的子模块
}

Groovy DSL (build.gradle)

plugins {
    id 'io.qameta.allure-aggregate-report'
}

allureAggregate {
    variants = ['debug']
    projects = [':core', ':feature', ':onscene', ':app']
}

3. 清理缓存并重新构建

执行以下命令清除构建缓存,重新生成聚合报告:

./gradlew clean
./gradlew allureAggregateReport

4. 统一插件版本

在根模块的settings.gradle.kts(或settings.gradle)中统一管理Allure插件版本,避免版本不一致问题:

Kotlin DSL (settings.gradle.kts)

pluginManagement {
    plugins {
        id("io.qameta.allure-adapter") version "2.24.0"
        id("io.qameta.allure-aggregate-report") version "2.24.0"
    }
}

内容的提问来源于stack exchange,提问作者Mark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:12:39