Where do gradle unit tests for Google app engine expect persistence.xml?
Asked Answered
T

1

45

I have created a Google app engine project using an maven archetype project with the Datanucleus JPA provider, essentially following the Google app engine documentation.

Everything works fine when running the maven goal "test".

Now I had to integrate the project into Android studio and wanted to migrate the build script to gradle. I copied all dependencies from the pom.xml to the build.gradle and the project builds fine. However, all tests that access the Google datastore fail.

During test output I get the following message:

Warning:No META-INF/persistence.xml files were found in the CLASSPATH of the current thread!

I checked the build folder which is created during the build and no folder contains the persistence.xml from src/main/webapp/WEB-INF/classes/META-INF

Using maven, however, it is correctly put in the target/myapp-1.0-SNAPSHOT/WEB-INF/classes/META-INF folder.

I have tried copying the persistence.xml using a gradle copy task into various locations, such as build/classes/META-INF build/classes/webapp/WEB-INF/classes/META-INF and so on, but nothing worked.

Tamayo answered 24/3, 2015 at 11:2 Comment(5)
While I certainly do not know enough about gradle, etc. to definitively answer this, the almighty Goog has given me this SO question which may help.Crampton
Thank you for pointing this out. However, my project is building the WAR fine. The persistence.xml is correctly put into the WEB-INF/classes/META-INF folder. This is not the issue. The issue is that when running the unit tests (where no WAR is being build), the persistence.xml has to be put somewhere. I am asking for this somewhere.Tamayo
my approach would be to put 1 in each folder until it runs :) that seems lame but has proven to be effectiveWhitten
@Whitten you can literally put them everywhere and do a binary search…Evictee
related? #15397836Outsoar
C
15

Just because the file is placed in a directory doesn't automatically mean it's in the CLASSPATH.

Place the META-INF folder containing persistence.xml in /src/main/resources.

Cistaceous answered 27/3, 2015 at 21:14 Comment(5)
This is actually correct. Thank you a thousand times. But can you maybe elaborate a bit further, why Gradle build expects the file under resources when web files should go under webapp?Tamayo
He probably would, if he hadn't (most likely) copied his answer without knowing what it meant from a comment on this answer, from the question Travis J linked.Rollet
check out this answer for more info about how mvn rearranges things #1297973Cistaceous
As the link skullkid posted says, Maven has the convention that all non-source files for source set main should go into src/main/resources. Gradle follows that Maven convention, unless you tell it otherwise.Constance
I do not want to stress this any further, but Maven builds fine with the file placed under webapp and Gradle does not. Of course, this could mean that Gradle follows Maven conventions stricter than Maven itself.Tamayo

© 2022 - 2024 — McMap. All rights reserved.