簡體   English   中英

告訴gradle從src / test / resources而不是src / main / resources中選擇persistence.xml

[英]Tell gradle to pick persistence.xml from src/test/resources instead of src/main/resources

我有一個Gradle Java Web項目正在開發,可在Wildfly中運行,結構如下:

- 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'
} 

源文件夾src/test/resourcespersistence.xml文件是我在運行測試時要使用的文件,而不是src/main/resources的另一個文件。
我需要這樣做,因為來自src/main/resources persistence.xml依賴於Java EE應用程序服務器中定義的JTA數據源,因此,我認為它不適用於本地執行。
如何配置gradle test命令在Eclipse和Gradle內部成功運行gradle test

提前致謝。

要解決此問題,請按照以下說明進行操作:

在Eclipse的項目屬性Java Build Path-> Order and Export中,將測試文件夾放在src文件夾上方。

以及談論另一個問題: 根據生產或測試環境,在Eclipse中使用不同的JPA.persistence.xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM