gradle test classnotfoundexception for compileOnly dependency

时间:2016-06-14 20:31:54

标签: java unit-testing gradle war

我有一个战争项目,我正在尝试运行我的单元测试。不幸的是,我收到的这个ClassNotFoundException是一个' compileOnly'依赖。我花了好几个小时尝试将此类添加到测试类路径中,但没有成功。任何帮助表示赞赏。

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

1 个答案:

答案 0 :(得分:1)

我不得不深入挖掘异常堆栈,当我这样做时,我发现我错过了依赖。