首页 > 解决方案 > 将参数传递给 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'
}

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

标签: javagradlegroovyclosuresbuild.gradle

解决方案


你的原始表达式将线程设置为一个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'
}

希望这可以帮助。


推荐阅读