简体   繁体   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

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/resourcespersistence.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.

相关问题 Gradle和src / main / resources - Gradle and src/main/resources 让 Eclipse 使用 src/test/resources 而不是 src/main/resources - Make Eclipse use src/test/resources instead of src/main/resources 来自src / test的persistence.xml中的类自动检测 - Class autodetection in persistence.xml from src/test 如何从src / main / java中的src / test / resources中读取道具 - How to read props from src/test/resources in src/main/java Spring xml + JUnit-xml上下文文件在src / test / resources中不起作用,但是在src / main / resources中起作用 - Spring xml + JUnit - xml context file not working in src/test/resources but works in src/main/resources 如何指示Maven忽略我的main / resources / persistence.xml以支持test / ...? - How to instruct Maven to ignore my main/resources/persistence.xml in favor of test/…? 使用 src/test/resources 作为 gradle java 的目录 - Use src/test/resources as directory with gradle java Spring启动测试没有从src / main / resources中获取hbm.xml文件 - Spring boot test not picking up hbm.xml files from src/main/resources 如何在JUnit测试中从src / main / resources中读取文件? - How to read file from src/main/resources relative in a JUnit test? 无法从 src/main/resources 加载 dispatcher-servlet.xml - Cannot load dispatcher-servlet.xml from src/main/resources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM