我有一个 war 项目,我正在尝试运行我的单元测试。不幸的是,我收到了一个属于“compileOnly”依赖项的类的 ClassNotFoundException 异常。我花了几个小时尝试将此类添加到测试类路径中,但没有成功。如有任何帮助,我们将不胜感激。
Gradle 构建文件如下:
buildscript {
repositories {
mavenCentral()
maven {
name = 'Sonatype Nexus Snapshots'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.1-SNAPSHOT'
}
}
plugins {
id 'eclipse-wtp'
id 'war'
id 'org.unbroken-dome.test-sets' version '1.2.0'
}
apply plugin: 'liberty'
compileJava.options.fork = true
compileJava.options.forkOptions.executable = project.property('JDKPath')
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
flatDir {
dirs 'WebContent/WEB-INF/lib'
}
}
configurations {
testCompile.extendsFrom compileOnly
testRuntime.extendsFrom compileOnly
}
testSets {
integrationTest
endToEndTest
}
dependencies {
// Libraries that will be provided by WebSphere.
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
compileOnly group: 'com.ibm.websphere.appserver.api', name: 'com.ibm.websphere.appserver.api.json', version: '1.0.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'com.jayway.restassured', name: 'rest-assured', version: '2.9.0'
}
sourceSets {
test {
compileClasspath += [configurations.compileOnly]
runtimeClasspath += [configurations.compileOnly]
}
}
最佳答案
我必须深入挖掘异常堆栈,当我这样做时,我发现我缺少一个依赖项。
关于java - gradle 测试compileOnly 依赖项的 classnotfoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37821563/