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

使用Gradle Wrapper 8.2.1从Java 11升级到17时遇属性设置错误

解决Gradle 8.2.1升级后JUnit Platform的binResultsDir属性错误

Gradle升级到8.2.1并同步Java版本到17后,出现Could not set unknown property 'binresultsdir' for object of type org.gradle.api.tasks.testing.junitplatform.junitplatformoptions错误,原因是Gradle 8.x版本移除了JUnitPlatformOptions类中的binResultsDir属性,旧配置方式不再适用。

错误代码

binResultsDir = file("$buildDir/test-results/acceptanceTest-${profile}-${label}/binary")

解决方案

将旧的binResultsDir配置替换为Gradle 8.x支持的binaryResultsDirectory属性,具体有两种配置方式:

方式一:通过测试套件(Test Suite)配置

如果项目使用Gradle的测试套件结构,可在testing扩展中配置:

testing {
    suites {
        acceptanceTest { // 替换为你的测试任务名称
            targets {
                all {
                    testTask.configure {
                        reports {
                            // 可选:配置JUnit XML报告路径(如果需要)
                            junitXml {
                                outputLocation = file("$buildDir/test-results/acceptanceTest-${profile}-${label}")
                            }
                            // 配置二进制测试结果目录
                            binaryResultsDirectory = file("$buildDir/test-results/acceptanceTest-${profile}-${label}/binary")
                        }
                    }
                }
            }
        }
    }
}

方式二:直接针对测试任务配置

如果是单独配置指定测试任务,可通过tasks.named定位任务后修改:

tasks.named('acceptanceTest', Test) {
    reports {
        binaryResultsDirectory = file("$buildDir/test-results/acceptanceTest-${profile}-${label}/binary")
    }
}

说明

Gradle 8.x对测试任务的配置体系做了重构,原JUnitPlatformOptions的部分属性被迁移到测试任务的reports块中,binaryResultsDirectory就是用来替代旧binResultsDir的属性,负责指定二进制测试结果的存储路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 10:27:04