I have two projects, one of which is an Intellij Plugin and the other is a library used by the plugin.
The library uses Jpa with hibernate as provider. Following the persistence.xml file which is located in the META-INF folder of the library:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<persistence-unit name="default">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.annotation.DBAnnotation</class>
<class>model.annotation.jpakeys.AnnotationKey</class>
<class>model.annotation.DBPosition</class>
<class>model.annotation.DBRange</class>
<class>model.metainfo.Asset</class>
<class>model.metainfo.Issue</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="*****************"/>
<property name="javax.persistence.jdbc.user" value="****************"/>
<property name="javax.persistence.jdbc.password" value="*****************"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.connection.autocommit" value="true"/>
</properties>
</persistence-unit>
</persistence>
and the build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0'
repositories {
mavenCentral()
}
dependencies {
compileOnly('javax.ejb:javax.ejb-api:3.2.2')
implementation('org.hibernate:hibernate-core:5.4.0.Final')
implementation('mysql:mysql-connector-java:8.0.13')
implementation ('org.mariadb.jdbc:mariadb-java-client:3.0.6')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
// jpa
implementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.2.RELEASE'
// git communication
implementation group: 'org.gitlab4j', name: 'gitlab4j-api', version: '5.0.1'
// used for .env variable
implementation('io.github.cdimascio:java-dotenv:5.2.2')
// json packages
implementation('org.json:json:20220320')
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
// caching
implementation('com.google.guava:guava:31.1-jre')
implementation('com.github.ben-manes.caffeine:caffeine:3.1.1')
// internal project/jar mapping
implementation project(":meta-parser")
implementation project(":model")
}
When i build the library into a fat-jar file everything runs fine and a proper db connection is being established. However if I start the plugin which uses the library i get a "No Persistence provider for EntityManager named" exception while startup.
The build.gradle of the plugin:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.1.6'
}
group ''
version '1.2'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
implementation project(":code-annotation-metainfo-lib")
}
// Ultimate kompatibel
intellij {
version = '2021.3.3'//
type = 'IU' //'IU'
//plugins = ['JavaScriptLanguage', 'com.intellij.java', 'com.jetbrains.php:212.5284.49']
}
and the settings.gradle:
rootProject.name = 'code-annotation-tool'
include ':code-annotation-metainfo-lib'
project(':code-annotation-metainfo-lib').projectDir = new File("../../code-annotation-metainfo-lib/code-annotation-metainfo-lib")
I run the plugin by the gradle 'runIde' task
Does anyone know wheter it is a packaging or a configuration problem and if yes how to fix it?
Alternitavley I do already use an seperate .env file to store the database properties and read them while runtime. Is there a possibility to also store the persistance unit in the .env file and read it in in runtime?