Search code examples
hibernategradle

How to setup Hibernate Gradle plugin for bytecode enhancement?


Hibernate Gradle plugin is an equivalent of hibernate-enhance-maven-plugin and offers build-time code enhancements. The official docs do not mention the apply plugin: 'something' line. If I just do as the guide says I get:

Could not find method hibernate() for arguments...

I tried guessing the plugin name with apply plugin: 'enhance' (as this thread suggests) and apply plugin: 'org.hibernate.orm' (as this test suggests) but it just says the plugin with that id is unknown.

Has anyone managed to set this plugin up successfully?

My build.gradle is as follows:

allprojects {
    group 'xxx'
    version '1.0-SNAPSHOT'
}

subprojects {
    apply plugin: 'java'

    sourceCompatibility = 1.8

    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        ...
    }
}

project(':xxx-model') {
    buildscript {
       repositories {
           mavenLocal()
           mavenCentral()
       }
       dependencies {
           classpath "org.hibernate:hibernate-gradle-plugin:5.0.7.Final"
       }
    }

    apply plugin: 'org.hibernate.orm'

    hibernate {
        enhance {}
    }
}

... more unrelated project blocks here

Experimented with moving the buildscript{...} into the root, allprojects and subprojects with no useful results.


Solution

  • apply plugin: 'org.hibernate.orm'
    

    The plugin code indicates what you got from the test is correct. What you may be missing is a repositories section inside your buildScript section, to fetch the plugin jar from.