在Gradle中进行集成测试时找不到持久化类

时间:2013-02-07 03:19:02

标签: spring hibernate jpa gradle

我的项目基于Spring + JPA + Hibernate,之前使用Ant来管理构建过程,现在我打算使用Gradle。在运行'gradle clean test'时,我得到了一个例外,如下所示:

  

[2013-02-07 11:01:36,703] [测试工作者] [警告] [QuerySplitter]没有为查询类找到持久化类:来自com.mpos.lottery.te.workingkey.domain.WorkingKey w其中w .createDateStr =:createDateStr和w.gpeId =:gpeId

     

[2013-02-07 11:01:36,718] [测试人员] [错误] [TEPortServlet] org.hibernate.QueryParameterException:无法找到命名参数[gpeId];嵌套异常是java.lang.IllegalArgumentException:org.hibernate.QueryParameterException:找不到命名参数[gpeId]

我已经在eclipse和Ant中运行了测试用例(不需要jetty),它通过了,所以我怀疑gradle中的一些不正确的配置导致了这个异常。

以下是我的gradle脚本:

apply plugin: 'war'
// 'war' plugin will apply 'java' plugin automatically
apply plugin: 'java'
apply plugin: 'eclipse'
// run web application, refer to http://gradle.org/docs/current/userguide/jetty_plugin.html
apply plugin: 'jetty'

compileJava.options.encoding = _sourcecode_encoding
compileTestJava.options.encoding = _sourcecode_encoding

// Properties added by the java plugin
sourceCompatibility="${_source_compatibility}"
targetCompatibility="${_target_compatibility}"
//Properties added by the 'war' plugin
webAppDirName="src/main/WWW"

configurations {
    provided {
        description = 'Non-exported comiple-time dependencies, it will be provided by container.'
    }
}

dependencies {
    provided files('lib/DEV/j2ee/servlet-api.jar')
    compile fileTree(dir: 'lib', include: '**/*.jar', exclude: 'DEV/**/*.jar')
    //compile sourceSets.main.output
    testCompile fileTree(dir:"lib", include:"DEV/**/*.jar")
}

sourceSets {
    main {
        compileClasspath = compileClasspath + configurations.provided
        //compileClasspath.collect().each({println it})
        resources {
            srcDir 'src/main/resource'
        }
    }
    test {
        resources {
            srcDir 'src/test/resource'
        }
    }
}

test {
    scanForTestClasses  = false
    classpath = configurations.provided + configurations.compile + configurations.testCompile + sourceSets.main.output + sourceSets.test.output
    classpath.each({println it})
    // customize test process
    include 'com/mpos/lottery/te/gameimpl/smsraffle/**/*Test.class'
}

我是Gradle和groovy的新学徒,请帮助我。提前谢谢。

1 个答案:

答案 0 :(得分:2)

默认情况下,Gradle对类和资源使用单独的输出目录,这可能会导致Hibernate / JPA出现问题。尝试:

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir

你可能不需要后者。