我通读了this ,官方Gradle reference和迁移guide ,而且我仍然无法弄清楚为什么以下构建脚本不起作用。
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
testImplementation group: 'org.testng', name: 'testng', version: '6.14.3'
}
def t_threads = test_threads
test {
useTestNG() {
setParallel('methods');
setThreadCount(t_threads)
}
maxParallelForks = t_threads
}
task printProps {
println test_threads
}
我的gradle.properties
文件:
test_threads = 1
gradle printProps
在 setThreadCount(t_threads)
行上失败,并出现异常:无法找到参数的方法 setThreadCount() 1在 org.gradle.api.tasks.testing.testng.TestNGOptions 类型的对象上。如果我将代码更改为 def t_threads = 1
,则 gradle printProps
完成时不会出现显示 1
的错误。
最佳答案
答案很简单。 setThreadCount
期望 Integer
作为参数,但属性是 String
,所以我所要做的就是转换 String
使用 test_threads 作为 Integer
转换为 Integer
。
关于java - 在 build.gradle 中使用 Gradle 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50892596/