Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate JPA Metamodel with Gradle 5.x

I am currently trying to upgrade from gradle 4.8.1 to 5.1.1 but fail with generating the hibernate metamodel for our code.

The problem is that gradle 5 ignores the annotation processor passed with the compile classpath, but all plugins I found are using this (i.e "-proc:only").

I tried to specify the annotation processor explicitly as pointed out by gradle (https://docs.gradle.org/4.6/release-notes.html#convenient-declaration-of-annotation-processor-dependencies) annotationProcessor 'org.hibernate:hibernate-jpamodelgen'

But this does not help and I still get the following error:

warning: Annotation processing without compilation requested but no processors were found.

Maybe also the plugins need to be updated, but as I said all plugins which I found are passing the annotation processor with the classpath. We are currently using this one: https://github.com/Catalysts/cat-gradle-plugins/tree/master/cat-gradle-hibernate-plugin

like image 240
FKorni Avatar asked Jan 16 '19 13:01

FKorni


People also ask

How do I generate the JPA entity metamodel?

In case of IDE Eclipse 1. goto Project->Properties->Java Compiler->Annotation Processing and enable it. 2. Expand Annotation Processing->Factory Path-> Add External Jar add Hibernate JPA 2 Metamodel Generator jar check the newly added jar and say OK.

What is metamodel in JPA?

JPA (Java persistence API) metamodel classes are classes that describe the structure of JPA entity classes (classes used to store database state as Java objects). They enable you to write Java code for creating database queries in a typesafe way.

What is Annotationprocessor gradle?

An annotation processor is a class which extends AbstractProcessor (in the package javax. annotation. processing ) providing the functionality needed to generate whatever it needs to generate, such as classes in the case of mapstruct.

What is metamodel in hibernate?

Hibernate Static Metamodel Generator is an annotation processor based on JSR_269 with the task of creating JPA 2 static metamodel classes. The following example shows two JPA 2 entities Order and Item , together with the metamodel class Order_ and a typesafe query.


1 Answers

you can just remove the plugin for the jpa modelgen and just use

annotationProcessor('org.hibernate:hibernate-jpamodelgen:<version>')

Addtionally i use those settings to configure where the generated code should live.

tasks.withType(JavaCompile) {
  options.annotationProcessorGeneratedSourcesDirectory = file("src/generated/java")
}


sourceSets {
    generated {
        java {
            srcDirs = ['src/generated/java']
        }
    }
}
like image 171
M. Schett Avatar answered Sep 20 '22 21:09

M. Schett