6

I want to use org.hibernate:hibernate-gradle-plugin in my project with plugins dsl style. This is my build.gradle.kts plugin section:

plugins {
    kotlin("jvm") version "1.3.31"
    id("io.spring.dependency-management") version "1.0.6.RELEASE"
    id("org.springframework.boot") version "2.1.5.RELEASE"
    id("org.jetbrains.kotlin.plugin.spring") version "1.3.31"
    id("org.jetbrains.kotlin.plugin.jpa") version "1.3.31"
}

Does anybody knows how to do this?

All of the documentation and posts are using the legacy plugin application. Like this: How to setup Hibernate Gradle plugin for bytecode enhancement?

eszik.k
  • 1,729
  • 4
  • 17
  • 40

2 Answers2

14

It looks like they haven't registered this plugin in the Gradle Plugins Repository which rules out using the newer DSL without using a custom plugin resolution strategy.

For your case in build.gradle.kts

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

And in settings.gradle.kts

pluginManagement {
    resolutionStrategy {
        eachPlugin { 
            if (requested.id.id == "org.hibernate.orm") { 
                useModule("org.hibernate:hibernate-gradle-plugin:${requested.version}") 
            } 
        } 
    }
}
MarkRobbo
  • 975
  • 1
  • 9
  • 31
  • Yes, resolution startegy solved my problem. I wrote this in build.gradle.kts `id("org.hibernate.orm") version "5.4.3.Final"` and this to `settings.gradle.kts` `resolutionStrategy { eachPlugin { if (requested.id.id == "org.hibernate.orm") { useModule("org.hibernate:hibernate-gradle-plugin:${requested.version}") } } }` – eszik.k Jun 05 '19 at 10:47
  • 1
    @aszik.k awesome! Glad you got it working. I'll add that to the answer for completeness – MarkRobbo Jun 06 '19 at 11:23
  • Does this work? I don't get any information in the console that the feature is enabled – mleister May 31 '20 at 19:23
  • 1
    Thanks. It seems that with Gradle version 6.6.1, the `resolutionStrategy` in `settings.gradle.kts` need to be wrapped in `pluginManagement { ... }` to work. – Dario Seidl Sep 16 '20 at 14:08
4

In addition to the perfectly working solution of @MarkRobbo you can use the following snippet to configure the options of the hibernate-gradle-plugin in build.gradle.kts

tasks.withType<org.hibernate.orm.tooling.gradle.EnhanceTask>().configureEach {
     options.enableLazyInitialization = true
}
Bernhard Kern
  • 208
  • 2
  • 10