简体   繁体   中英

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM