Gradle 格雷德尔:什么';TestNG的'excludeGroups'赋值有什么问题?

Gradle 格雷德尔:什么';TestNG的'excludeGroups'赋值有什么问题?,gradle,groovy,Gradle,Groovy,有一个我使用TestNG和Gradle的项目 build.gradle文件中的测试部分: tasks.withType(Test) { useTestNG() { useDefaultListeners = true testLogging.showStandardStreams = true } } /* some code there */ task integTest(type: Test) { useTestNG() {

有一个我使用TestNG和Gradle的项目
build.gradle文件中的测试部分:

tasks.withType(Test) {
    useTestNG() {
        useDefaultListeners = true
        testLogging.showStandardStreams = true
    }
}

/*
    some code there
*/

task integTest(type: Test) {
    useTestNG() {
        excludeGroups = ['jt-someTest2', 'jt-someTest3'].toSet()
    }
}
在这种情况下,一切正常。但当我尝试这样的方法时:

def allAvailableTestGroups = ['someTest1', 'someTest2', 'someTest3'].toSet()
def testGroup = project.hasProperty("testGroup") ? project.testGroup : 'all'


tasks.withType(Test) {
    useTestNG() {
        useDefaultListeners = true
        testLogging.showStandardStreams = true
    }
}

/*
    ...
    some code there
    ...
*/

task integTest(type: Test) {
    useTestNG() {
        excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}" }.findAll { it != testGroup } ) as HashSet<String>
    }
}
def allAvailableTestGroups=['someTest1','someTest2','someTest3']
def testGroup=project.hasProperty(“testGroup”)?project.testGroup:“全部”
任务。withType(测试){
useTestNG(){
useDefaultListeners=true
testLogging.showStandardStreams=true
}
}
/*
...
那里有一些代码
...
*/
任务集成测试(类型:测试){
useTestNG(){
excludeGroups=(allAvailableTestGroups.collect{“jt-${it}}}.findAll{it!=testGroup})作为哈希集
}
}
我遇到了这样的麻烦:

org.gradle.internal.UncheckedException: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.GStringImpl
//…
原因:java.lang.ClassNotFoundException:org.codehaus.groovy.runtime.GStringImpl
//…
引发意外异常。
org.gradle.internal.remote.internal.MessageIOException:无法读取 来自“/127.0.0.1:58219”的消息。
//…
原因:com.esotericsoftware.kryo.KryoException:java.io.IOException:╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўэцц
//…
原因:java.io.IOException:╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўэцц
//…
引发意外异常。
org.gradle.internal.remote.internal.MessageIOException:无法 写“/127.0.0.1:58219”。
//…
原因:java.io.IOException:╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўэцц
//…
:集成测试失败
失败:生成失败,出现异常

怎么了?

替换此行:

excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}" }
    .findAll { it != testGroup } ) as HashSet<String>

Groovy编译器似乎由于某种原因缺少GString
“jt-$it”
的自动翻译。。。调用
toString()
应该可以解决这个问题。

你也应该问你的问题
excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}".toString() }
    .findAll { it != testGroup } ) as Set