How to enable Hibernate Bytecode enhancement in gradle

Viewed 731

How to enable the plugin with gradle? Unfortunately it's not working for me with the current setup:

build.gradle.kts:

plugins {
    id("org.hibernate.orm") version "5.4.17.Final"
}

tasks.withType<org.hibernate.orm.tooling.gradle.EnhanceTask>().configureEach {
    options.enableLazyInitialization = true
    options.enableDirtyTracking = true
    options.enableAssociationManagement = true
}

settings.gradle.kts:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "org.hibernate.orm") {
                useModule("org.hibernate:hibernate-gradle-plugin:${requested.version}")
            }
        }
    }
}

I am not sure if its working or not, how can I check if the plugin is enabled? There is no console output or something like that. Also some features are not working which SHOULD work when the plugin is setted up correctly.

1 Answers

Such a nice way to resolve the plugin dependency!

Here is what I believe the correct way to configure the plugin using Kotlin DSL

hibernate {
    enhance(closureOf<org.hibernate.orm.tooling.gradle.EnhanceExtension> {
        enableLazyInitialization = true
        enableDirtyTracking = true
        enableAssociationManagement = true
        enableExtendedEnhancement = false
    })
}

This should work well on Java code, but not always on Kotlin on incremental builds. You must also need to have Java source set to trigger the instrument.

Related