java - build.gradle 中使用 Gradle 属性
问题描述
我通读了这个,官方 Gradle参考和迁移指南,但我仍然无法弄清楚为什么以下构建脚本不起作用。
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)
出现异常:在 org.gradle.api.tasks.testing.testng.TestNGOptions类型的对象上找不到参数1的方法 setThreadCount()。如果我将代码更改为def t_threads = 1
,则gradle printProps
完成后不会显示错误1
。
解决方案
答案很简单。setThreadCount
期望Integer
作为参数,但属性是 a String
,所以我所要做的就是转换String
为Integer
using test_threads as Integer
。
推荐阅读
- java - JAVA 8 SIGSEGV 上的 Java 崩溃 (0xb)
- r - 如何使用 purrr::accumulate 进行累积过滤?
- node.js - 在 adf-cli-acs-aps-template@3.5.0 启动脚本失败
- c++ - 是否可以在 gcc 中仅启用特定的 C++ 语言功能?
- java - 投掷类
- vba - VBA - 对象被拒绝
- javascript - 如何从灯箱画廊中触发无限滚动 - Django / FancyBox / Waypoints.js
- google-cloud-platform - 计算实例在 100% CPU 使用数小时后被删除
- c# - 使用 AT 命令发送包含表情符号的短信
- flutter - 如何更改颤动中图表的默认调色板?