1

I am trying to setup the Hibernate gradle plugin in my Gradle Kotlin-script project, to no avail.

I followed the answers here and here, my configuration is as follows:

settings.gradle.kts:

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

build.gradle.kts

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

...

hibernate {
  enhance {  }
}

I am getting an error from Gradle:

  Line 193:   enhance {}
                      ^ Type mismatch: inferred type is () -> Unit but (Closure<Any!>..Closure<*>?) was expected

I also tried with the following hibernate block:

hibernate {
  enhance {
    enableLazyInitialization = true
    enableDirtyTracking = true
    enableAssociationManagement = true
  }
}

but i'm just getting more errors:

  Line 193:   enhance {
                      ^ Type mismatch: inferred type is () -> Unit but (Closure<Any!>..Closure<*>?) was expected

  Line 194:     enableLazyInitialization = true
                ^ Unresolved reference: enableLazyInitialization

  Line 195:     enableDirtyTracking = true
                ^ Unresolved reference: enableDirtyTracking

  Line 196:     enableAssociationManagement = true
                ^ Unresolved reference: enableAssociationManagement

Anyone knows how to make this work in Kotlin-script?

gotson
  • 3,613
  • 1
  • 23
  • 40
  • can you try import `import org.hibernate.orm.tooling.gradle.EnhanceExtension`, – dkb Dec 17 '19 at 08:57
  • 2
    Also add `hibernate { enhance(closureOf { enableLazyInitialization = true enableDirtyTracking = true enableAssociationManagement = true }) }`, remove older config you have, rest all will remain same. – dkb Dec 17 '19 at 08:57
  • Thanks, Gradle doesn't complain anymore, however it seems my classes are not enhanced, even after a `gradle clean`. When i check the decompiled class there is nothing that looks like hibernate enhancements in my classes. – gotson Dec 17 '19 at 09:59
  • 1
    wouldn't that be an another issue, Ref: https://discourse.hibernate.org/t/how-to-see-if-bytecode-enhancement-works-or-not/1044/4, https://stackoverflow.com/q/50570793/2987755 – dkb Dec 17 '19 at 10:24
  • 1
    that's the link i was looking at, but i can't make it work with kotlin sourceSets, i think that's the problem. I have 100% kotlin code, no java code, and all my code in `src/main/kotlin` – gotson Dec 17 '19 at 10:27
  • Got, I really hate the kotlin gradle syntax. Nothing works as expected. Regreting every day, I ever used it. – spyro Oct 27 '21 at 12:45

0 Answers0