英文:
Gradle exclude local jar during testRunTime
问题
我在这里有以下情况... 我的 Gradle jar
目标在编译时需要 javaee-api-*.jar
作为 compile
依赖
dependencies {
compile fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
但是,在执行 Gradle test
时,我需要以下方式的 dependencies
...
dependencies {
compileOnly fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
在 testRunTime
期间如何排除一个 JAR 文件?
英文:
I've below situation here... My Gradle jar
target needs javaee-api-*.jar
as a compile
time
dependencies {
compile fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
But, during Gradle test
execution I need dependencies
as below...
dependencies {
compileOnly fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
How should I exclude a jar during testRunTime
?
答案1
得分: 0
我从project.sourceSets.test.runtimeClasspath.filter
中过滤掉了javaee-api-*.jar
。
将javaee-api-*.jar
添加为编译依赖项。
dependencies {
compile fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
还有
sourceSets {
....
test {
runtimeClasspath = project.sourceSets.test.runtimeClasspath.filter {
!it.path.endsWith('oraclejavaee/javaee-api-6.0.jar')
}
java.srcDir project(':test-framework').file("src")
resources.srcDirs project(':test-framework').file("config")
}
}
并且在以下位置添加dependOn
test {
dependsOn(testClasses)
useTestNG() {
useDefaultListeners = true
suites 'test/testng.xml'
}
}
英文:
I filtered out javaee-api-*.jar
from project.sourceSets.test.runtimeClasspath.filter
added javaee-api-*.jar
as a compile dependuncy
dependencies {
compile fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
and
sourceSets {
....
test {
runtimeClasspath = project.sourceSets.test.runtimeClasspath.filter {
!it.path.endsWith('oraclejavaee/javaee-api-6.0.jar')
}
java.srcDir project(':test-framework').file("src")
resources.srcDirs project(':test-framework').file("config")
}
}
and adding dependOn
in
test {
dependsOn(testClasses)
useTestNG() { //Tells Gradle to use TestNG
useDefaultListeners = true // Tells TestNG to execute its default reporting structure
suites 'test/testng.xml' //location of our suite.xml
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论