java - gradle 测试compileOnly 依赖项的 classnotfoundException

标签 java unit-testing gradle war

我有一个 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/

相关文章:

java - 链接到子类中的另一个构造函数

reactjs - Typescript + React 测试库 - 'SidebarItem' 指的是一个值,但在这里被用作类型。你的意思是 'typeof SidebarItem' ?ts(2749)

android - 将数据从 settings.gradle 传递到 build.gradle

android - 错误: resource android:attr/colorError not found

java - Selenium、Chrome 的 WebDriver 停止窗口打开

javascript - 从 JavaScript 获取值到 Bean

java - Java 中的类型文字是什么?

c# - 测试资源管理器不显示网络驱动器的单元测试列表

javascript - 如何使用 chai 检查元素类型?

android - 如何将 SimMetrics 导入 Android Studio 项目?