Gradle, Hibernate and “No Persistence provider for EntityManager named”

During the actual migration of an JEE project, consisting of several moduls (WAR, EJB ..) from Ant to Gradle I faced the following problem:

In the test phase, e.g. when calling gradle test, one integration test (or should it better be called functional test? I’m not sure about this) stated out that:

No Persistence provider for EntityManager named myTestPersistenceUnit

So what’s the problem here? I looked through my dependencies and everything looks great.

The first thing I stumbled upon was, that I need to put the persistence.xml in the META-INF folder, because Gradle doesn’t copy it to this folder. An big difference from the Ant buildscript.
But that change didn’t fix it.
After reading and searching many hints and tips I figured out, that the next problem was, that I need to import also this dependency

Now this exception was gone but a new one occured


But I’ve already defined this dependency! What’s now the problem? The last problem was, that I need to change the used version from 3.1.0.GA to 4.2.0.Final of ‘org.hibernate:hibernate-validator’. This must be done, because the version 3.1.0.GA isn’t an implementation of the JSR303 provider.

So that was hard work, but finally I’m now able to kill the Ant Skript and ended up with this compile dependencies:

0 Kudos

2 thoughts on “Gradle, Hibernate and “No Persistence provider for EntityManager named”

Leave a Reply

Your email address will not be published. Required fields are marked *