[英]Tell gradle to pick persistence.xml from src/test/resources instead of src/main/resources
I have a Gradle java web project being developed to run in Wildfly with the following structure: 我有一个Gradle Java Web项目正在开发,可在Wildfly中运行,结构如下:
- src/main/java
- src/main/resources
\-- META/INF
\-- persistence.xml
- src/test/java
- stc/test/resources
\-- META/INF
\-- persistence.xml
And the following build.gradle
: 和以下build.gradle
:
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.8
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Arch Project', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
configurations {
provided
}
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
dependencies {
/* Java EE 7 API. */
provided 'javax:javaee-api:7.0'
/* JUnit for unit testing. */
testCompile 'junit:junit:4.1.2'
/* DbUnit - Persitence unit testing. */
testCompile 'org.dbunit:dbunit:2.5.0'
testCompile 'org.slf4j:slf4j-simple:1.7.9'
/* Hibernate. */
testCompile 'org.hibernate:hibernate-core:4.3.7.Final'
/* Hibernate provider for JPA. */
testCompile 'org.hibernate:hibernate-entitymanager:4.3.7.Final'
/* Hibernate dependency. */
testCompile 'com.fasterxml:classmate:1.1.0'
/* PostgreSQL for persistence tests context */
testCompile 'org.postgresql:postgresql:9.3-1102-jdbc41'
}
The persistence.xml
file in the source folder src/test/resources
is the one that I want to be used when I run my tests, instead the another from src/main/resources
. 源文件夹src/test/resources
的persistence.xml
文件是我在运行测试时要使用的文件,而不是src/main/resources
的另一个文件。
I need that because persistence.xml
from src/main/resources
relies on a JTA datasource defined in the Java EE application server, so, I believe it is not going to work on a local execution. 我需要这样做,因为来自src/main/resources
persistence.xml
依赖于Java EE应用程序服务器中定义的JTA数据源,因此,我认为它不适用于本地执行。
How can I configure that to run the tests successfully inside Eclipse and Gradle by the command gradle test
? 如何配置gradle test
命令在Eclipse和Gradle内部成功运行gradle test
?
Thanks in advance. 提前致谢。
to resolve this problem follow these instructions: 要解决此问题,请按照以下说明进行操作:
In Eclipse's project properties, Java Build Path->Order and Export, put your test folder above your src folder. 在Eclipse的项目属性Java Build Path-> Order and Export中,将测试文件夹放在src文件夹上方。
as well as talk that another issue: Use different JPA.persistence.xml in Eclipse depending on production or test environment 以及谈论另一个问题: 根据生产或测试环境,在Eclipse中使用不同的JPA.persistence.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.