Module not found when running tests in Maven

Hi, I'm trying to create a modular application for fetching articles from popular news sources in Poland. A part of the app is a module saving these articles into a database using Hibernate. I wrote a couple of tests for this module and when I run them through intellij they work just fine, but when I try to use Maven it throws errors like these:
[ERROR] Error occurred during initialization of boot layer
[ERROR] java.lang.module.FindException: Module jakarta.cdi not found, required by jakarta.transaction
[ERROR] Error occurred during initialization of boot layer
[ERROR] java.lang.module.FindException: Module jakarta.cdi not found, required by jakarta.transaction
What should I do to fix this? Github link to the project: https://github.com/Eukon05/infodb/tree/hibernate The class that is responsible for these tests is "HibernateDAOTests" in the "infodb-persistence-hibernate" module
19 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Eukon05! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st2mo ago
Can you show the dependency tree? What exactly are you starting such that you are getting the error? What is using jakarta.transaction? I assume it's just infodb-persistence-hibernate? Can you try adding jakarta.cdi as a dependency?
Eukon05
Eukon05OP2mo ago
--- dependency:3.7.0:tree (default-cli) @ infodb-persistence-hibernate ---
[INFO] ovh.eukon05:infodb-persistence-hibernate:jar:1.0-SNAPSHOT
[INFO] +- ovh.eukon05:infodb-api-persistence:jar:1.0-SNAPSHOT:compile
[INFO] +- org.hibernate.orm:hibernate-core:jar:6.6.1.Final:compile
[INFO] | +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] | +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.5.0.Final:runtime
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:7.0.1.Final:runtime
[INFO] | +- io.smallrye:jandex:jar:3.2.0:runtime
[INFO] | +- com.fasterxml:classmate:jar:1.5.1:runtime
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.14.18:runtime
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:runtime
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.0:runtime
[INFO] | +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.2:runtime
[INFO] | | \- org.glassfish.jaxb:jaxb-core:jar:4.0.2:runtime
[INFO] | | +- org.eclipse.angus:angus-activation:jar:2.0.0:runtime
[INFO] | | +- org.glassfish.jaxb:txw2:jar:4.0.2:runtime
[INFO] | | \- com.sun.istack:istack-commons-runtime:jar:4.1.1:runtime
[INFO] | +- jakarta.inject:jakarta.inject-api:jar:2.0.1:runtime
[INFO] | \- org.antlr:antlr4-runtime:jar:4.13.0:runtime
[INFO] +- com.h2database:h2:jar:2.3.232:test
[INFO] \- org.junit.jupiter:junit-jupiter:jar:5.11.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.11.2:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | +- org.junit.platform:junit-platform-commons:jar:1.11.2:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-params:jar:5.11.2:test
[INFO] \- org.junit.jupiter:junit-jupiter-engine:jar:5.11.2:test
[INFO] \- org.junit.platform:junit-platform-engine:jar:1.11.2:test
--- dependency:3.7.0:tree (default-cli) @ infodb-persistence-hibernate ---
[INFO] ovh.eukon05:infodb-persistence-hibernate:jar:1.0-SNAPSHOT
[INFO] +- ovh.eukon05:infodb-api-persistence:jar:1.0-SNAPSHOT:compile
[INFO] +- org.hibernate.orm:hibernate-core:jar:6.6.1.Final:compile
[INFO] | +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] | +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.5.0.Final:runtime
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:7.0.1.Final:runtime
[INFO] | +- io.smallrye:jandex:jar:3.2.0:runtime
[INFO] | +- com.fasterxml:classmate:jar:1.5.1:runtime
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.14.18:runtime
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:runtime
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.0:runtime
[INFO] | +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.2:runtime
[INFO] | | \- org.glassfish.jaxb:jaxb-core:jar:4.0.2:runtime
[INFO] | | +- org.eclipse.angus:angus-activation:jar:2.0.0:runtime
[INFO] | | +- org.glassfish.jaxb:txw2:jar:4.0.2:runtime
[INFO] | | \- com.sun.istack:istack-commons-runtime:jar:4.1.1:runtime
[INFO] | +- jakarta.inject:jakarta.inject-api:jar:2.0.1:runtime
[INFO] | \- org.antlr:antlr4-runtime:jar:4.13.0:runtime
[INFO] +- com.h2database:h2:jar:2.3.232:test
[INFO] \- org.junit.jupiter:junit-jupiter:jar:5.11.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.11.2:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | +- org.junit.platform:junit-platform-commons:jar:1.11.2:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-params:jar:5.11.2:test
[INFO] \- org.junit.jupiter:junit-jupiter-engine:jar:5.11.2:test
[INFO] \- org.junit.platform:junit-platform-engine:jar:1.11.2:test
dan1st
dan1st2mo ago
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.1</version>
</dependency>
if you get a similar error with jakarta.interceptor, you might need to add that as well in a similar way if necessary
<dependency>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
<version>2.0.1</version>
</dependency>
It's because Jakarta Transaction uses Jakarta CDI but declares it as a provided dependency: https://repo1.maven.org/maven2/jakarta/transaction/jakarta.transaction-api/2.0.1/jakarta.transaction-api-2.0.1.pom
Eukon05
Eukon05OP2mo ago
Now it went through, but then gave me another error:
Caused by: jakarta.persistence.PersistenceException: No Persistence provider for EntityManager named hibernate
Caused by: jakarta.persistence.PersistenceException: No Persistence provider for EntityManager named hibernate
Should I create another persistence.xml file in the test/resources directory?
dan1st
dan1st2mo ago
I don't think that should be necessary
dan1st
dan1st2mo ago
You can try specifying a <provider> in your persistence.xml similar to https://stackoverflow.com/a/1285436/10871900
Stack Overflow
No Persistence provider for EntityManager named
I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with: EntityManagerFactory emfdb = Persistence.createEntityManagerFactory("...
Eukon05
Eukon05OP2mo ago
Ok, let me try that
dan1st
dan1st2mo ago
the class name of the provider may also be org.hibernate.jpa.HibernatePersistenceProvider make sure the provider you are using exists And you might also want to specify the hibernate dialect I think it should be that one
Eukon05
Eukon05OP2mo ago
It didn't help, I also get a warning before the error: WARNING: jakarta.persistence.spi::No valid providers found. I also tried making a copy of the persistence.xml file in the test dir. but it did nothing
dan1st
dan1st2mo ago
Does the class org.hibernate.jpa.HibernatePersistenceProvider exist anywhere in your dependencies?
Eukon05
Eukon05OP2mo ago
I tried to check if it's being loaded by the class loader with this in an @BeforeAll block:
try {
Class.forName("org.hibernate.jpa.HibernatePersistenceProvider");
System.out.println("LOADED");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Class.forName("org.hibernate.jpa.HibernatePersistenceProvider");
System.out.println("LOADED");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
But it fails and gives an error: java.lang.IllegalAccessError: superclass access check failed: class org.jboss.logging.JBossLogRecord (in module org.jboss.logging) cannot access class java.util.logging.LogRecord (in module java.logging) because module org.jboss.logging does not read module java.logging
dan1st
dan1st2mo ago
Can you show the full stack trace?
dan1st
dan1st2mo ago
You can try --add-reads org.jboss.logging=java.logging to the JVM args when running it
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Eukon05
Eukon05OP2mo ago
Sorry for a late response, I've just tried it and the tests went through! Thank you so much!
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2mo ago
Post Closed
This post has been closed by <@352745203322585088>.
Want results from more Discord servers?
Add your server