Gradle 在 testRunTime 时排除本地 jar 文件。

huangapple go评论80阅读模式
英文:

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
    }
}

huangapple
  • 本文由 发表于 2020年8月17日 16:31:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63447283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定