gpt4 book ai didi

gradle - integrationTestCompile gradle 依赖被忽略

转载 作者:行者123 更新时间:2023-12-03 02:53:13 24 4
gpt4 key购买 nike

在几篇博文之后,我尝试创建一个单独的源文件夹用于 gradle 中的集成测试。我还想向我的 integrationTest 任务添加一些附加的(arquillian)依赖项,但是 integrationTestCompile 似乎被忽略了,我得到一个编译错误,附加的依赖项没有解决。当我将依赖项更改为 testCompile 时,它​​工作正常。为什么会这样,如何改变呢?我的简单测试类:

//compilation fails with  [Static type checking] - The variable [ArquillianSputnik] is undeclared
@TypeChecked
@RunWith(ArquillianSputnik)
class TestSpec extends Specification {


}

和gradle.build:

apply plugin: 'groovy'
apply plugin: 'war'

war.dependsOn 'native2ascii'

task native2ascii << {

ant.delete() {
fileset(dir: "${processResources.destinationDir}") {
include(name: '*.properties')
}
}
ant.native2ascii(src: 'src/main/resources/',
dest: "${processResources.destinationDir}",
includes: '**/*.properties',
encoding: 'UTF-8')
}

repositories {
mavenCentral()
maven {
url 'http://repository.jboss.org/nexus/content/groups/public'
}
mavenLocal()
}

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs += ["src/main/java"]

sourceSets {
integrationTest {
groovy.srcDir file('src/integration-test/groovy')
resources.srcDir file('src/integration-test/resources')
compileClasspath = sourceSets.main.output + configurations.testCompile
runtimeClasspath = output + compileClasspath + configurations.testRuntime
}
}

dependencies {
//(...) non-test dependencies cut out for clarity

testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'cglib:cglib-nodep:2.2.2'
testCompile 'org.objenesis:objenesis:1.2'

//when integrationTestCompile is changed to testCompile the compilation works and the test is executed
integrationTestCompile 'org.jboss.arquillian.spock:arquillian-spock-container:1.0.0.Beta3'
integrationTestCompile 'org.jboss.arquillian.graphene:graphene-webdriver:2.0.3.Final'
integrationTestCompile 'org.jboss.as:jboss-as-arquillian-container-managed:7.2.0.Final'
}

task integrationTest(type: Test, dependsOn: 'test') {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath

}

check.dependsOn 'integrationTest'

最佳答案

首先,您想添加到编译和运行时类路径而不是替换它们。这实际上只是意味着使用 += 运算符而不是 = 运算符。此外,您实际上只想添加其他源集输出,我们将单独处理配置。

compileClasspath += sourcesets.main.output + sourcesets.test.output
runtimeClasspath += sourcesets.main.output + sourcesets.test.output

接下来,我们要配置我们的集成测试配置。通常,这只是意味着让他们扩展测试和编译测试,以便它们也包含所有这些依赖项。

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

关于gradle - integrationTestCompile gradle 依赖被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28903335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com