Chad
Chad

Reputation: 2071

JOOQ with Gradle and Kotlin do not generate files

I have the following gradle task in my build.gradle.kts. It's supposed to generate files from my JPA entities. However when running this task, upon succeeding, no file or directory is generated.

task(name = "generateJooq") {
    doLast {
        val configuration = Configuration().apply {

            generator = Generator().apply {
                database = Database().apply {
                    name = "org.jooq.util.jpa.JPADatabase"
                    properties = listOf(Property().apply {
                        key = "packages"
                        value = "com.example.sample"
                    })
                }

                target = Target().apply {
                    packageName = "com.example.jooq"
                    directory = "src/generated/java"
                }
            }
        }

        GenerationTool.generate(configuration)
    }
}

This is my entity living under package com.example.sample. Note that I wrote this entity in Java.

@Entity
public class Book {

    @Id
    private String id;

    @Column
    private String title;
}

Had the following logs

./gradlew clean generateJooq      

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed

Upvotes: 1

Views: 1292

Answers (1)

lance-java
lance-java

Reputation: 27994

I'm guessing that your Book class is in src/main/java correct?

And now you want that class to be available to JOOQ right? There's a bit of a chicken or egg problem where the Gradle buildscript classloader (which loads gradle tasks) is defined before src/main/java is compiled.

You'll need to pass a custom classloader to JOOQ (eg URLClassloader). JOOQ can then use the classloader to load the classes (hopefully the JOOQ API's support this). You can use sourceSets.main.runtimeClasspath to create an array of URL.

I see that GenerationTool has a setClassLoader(..) method here. I'm guessing you'll call that

See here for a similar solution (using Reflections rather than JOOQ but fundamentally the same).

Upvotes: 3

Related Questions