将参数传递给Gradle构建脚本

时间:2019-05-16 14:37:33

标签: java gradle build.gradle

我正在尝试在控制台中执行这样的命令:

./gradlew cucumber -Pthreads=80 -Ptags=@ALL_API_TESTS

在build.gradle中:

cucumber {
    threads = "$threads"
    glue = 'classpath:com.sixtleasing.cucumber.steps'
    plugin = ['pretty']
    tags = "$tags"
    featurePath = 'src/main/resources/feature'
    main = 'cucumber.api.cli.Main'
}

但是它不起作用:(我该如何解决?

1 个答案:

答案 0 :(得分:0)

您的原始表达式将线程设置为String值(显然它是数字值),因此您需要使用类似以下内容的方法:

int threadsNum = "$threads".toInteger()
cucumber {
    threads = threadsNum
    glue = 'classpath:com.sixtleasing.cucumber.steps'
    plugin = ['pretty']
    tags = "$tags"
    featurePath = 'src/main/resources/feature'
    main = 'cucumber.api.cli.Main'
}

希望这会有所帮助。