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