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.

itchee
  • 820
  • 5
  • 20
  • While I certainly do not know enough about gradle, etc. to definitively answer this, the almighty Goog has given me [this SO question](http://stackoverflow.com/questions/1279060/jpa-with-toplink-no-meta-inf-persistence-xml-was-found-in-classpath) which may help. – Becuzz Mar 27 '15 at 20:44
  • 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. – itchee Mar 27 '15 at 20:48
  • 5
    my approach would be to put 1 in each folder until it runs :) that seems lame but has proven to be effective – deW1 Mar 27 '15 at 20:50
  • 1
    @deW1 you can literally put them everywhere and do a binary search… – Display Name Mar 27 '15 at 21:09
  • related? http://stackoverflow.com/questions/15397336/no-persistence-providers-available-for-transactions-optional-after-trying-the – Travis J Mar 27 '15 at 21:53

1 Answers1

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.

Jongware
  • 22,200
  • 8
  • 54
  • 100
skullkid
  • 448
  • 4
  • 13
  • 4
    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`? – itchee Mar 28 '15 at 08:14
  • He probably would, if he hadn't *(most likely)* copied his answer without knowing what it meant from a comment on [this answer](http://stackoverflow.com/a/15403627/4686625), from the question Travis J linked. – miradulo Mar 28 '15 at 19:47
  • check out this answer for more info about how mvn rearranges things http://stackoverflow.com/questions/1297473/maven-including-a-meta-inf-folder-in-the-classes-folder – skullkid Mar 28 '15 at 20:45
  • 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. – Jolta Apr 03 '15 at 20:10
  • 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. – itchee Nov 02 '15 at 14:34