我有一個搖籃的Java Web項目正在開發中Wildfly具有以下結構運行的src /主/資源persistence.xml中:告訴gradle這個去摘的src /測試/資源,而不是
- src/main/java
- src/main/resources
\-- META/INF
\-- persistence.xml
- src/test/java
- stc/test/resources
\-- META/INF
\-- persistence.xml
而以下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'
}
的persistence.xml
文件中的源文件夾src/test/resources
是一個,我想,當我跑我的測試中使用,而不是另一名來自src/main/resources
。
我需要這樣做,因爲src/main/resources
中的persistence.xml
依賴於Java EE應用程序服務器中定義的JTA數據源,所以我相信它不會用於本地執行。
我該如何配置它才能通過命令gradle test
在Eclipse和Gradle內成功運行測試?
在此先感謝。
它是否幫助你以某種方式:http://forums.gradle.org/gradle/topics/resources_from_src_main_resources_not_included_for_test? – Opal 2015-02-01 08:59:05
Thx @Opal但它沒有幫助。如果我使用src/main/resources,那麼問題是我想從src/test/resources中使用'persistence.xml'。 – 2015-02-03 15:35:09