How to generate JPA Metamodel with Gradle 5.x

FKorni picture FKorni · Jan 16, 2019 · Viewed 8.7k times · Source

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

Answer

M. Schett picture M. Schett · Jan 28, 2019

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']
        }
    }
}