1

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

[2013-02-07 11:01:36,703][Test worker][WARN][QuerySplitter] 找不到查询类的持久类:来自 com.mpos.lottery.te.workingkey.domain.WorkingKey w 其中 w.createDateStr= :createDateStr 和 w.gpeId=:gpeId

[2013-02-07 11:01:36,718][Test worker][ERROR][TEPortServlet] org.hibernate.QueryParameterException:找不到命名参数 [gpeId];嵌套异常是 java.lang.IllegalArgumentException:org.hibernate.QueryParameterException:找不到命名参数 [gpeId]

我已经在 eclipse 和 Ant 中运行了那个测试用例(不需要码头),它通过了,所以我怀疑 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 的新手,请帮助我。提前致谢。

4

1 回答 1

2

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

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

您可能不需要后者。

于 2013-02-07T03:56:16.163 回答