I have a Gradle java web project being developed to run in Wildfly with the following structure:
- 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
:
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
.
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.
How can I configure that to run the tests successfully inside Eclipse and Gradle by the command 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.
as well as talk that another issue: Use different JPA.persistence.xml in Eclipse depending on production or test environment
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.