Hi Per,

thanks for the reply.  In my Gradle build file (it's using kts) I have this

sourceSets {
    this.main{
        kotlin.srcDir("$buildDir/generated/kotlin")
    }
}

tasks.create("generateJOOQ") {
    GenerationTool.generate(
        Configuration()
            .withBasedir("$buildDir")
            .withJdbc(
                Jdbc()
                    .withDriver("com.mysql.cj.jdbc.Driver")
                    .withUrl("jdbc:mysql://localhost:3306/xxx")
                    .withUser("xxx")
                    .withPassword("xxx")
            )

            .withGenerator(
                Generator()
                    .withName("org.jooq.codegen.KotlinGenerator")
                    .withDatabase(
                        Database()
                            .withInputSchema("mySchema")
                            .withName("org.jooq.meta.mysql.MySQLDatabase")
                    )
                    .withGenerate(Generate())
                    .withTarget(
                        Target()
                            .withPackageName("com.knowledgespike.db")
                            .withDirectory("generated/kotlin")
                            .withClean(true)
                    )
            )
    )
}


I have to specify the withBaseDir here otherwise the output is lost
(or at least appears to be lost),

Kevin


On Wed, Aug 2, 2023 at 11:55 AM Per Lundberg <[email protected]> wrote:

> Hi Kevin,
>
> Late to the party but I happened to see this thread now in my inbox. We
> also run our codegen via Gradle, using a custom source set named "codegen".
> We definitely don't have to specify any fully qualified path names, so this
> problem seems a bit odd indeed. Here's an excerpt from our build.gradle:
>
> tasks.register( 'createAuditLoggingDbJooqDomainClasses', JavaExec ) {
>     mainClass =
> 'fi.hibox.centre.audit.db.codegen.CreateAuditLoggingDbJooqDomainClasses'
>     classpath = sourceSets.codegen.runtimeClasspath
>
>     inputs.files( fileTree( 'src/codegen' ) )
>     inputs.files( fileTree( 'src/main' ) )
>
>     args( 'src/generated/java', 'fi.hibox.centre.audit.db.domain' )
>     outputs.dir( 'src/generated/java' )
> }
>
>
> (The CreateAuditLoggingDbJooqDomainClasses class is a Java console
> application which calls the org.jooq.codegen.GenerationTool class to run
> the code generation. It was convenient for us to wrap this in a Java class
> so we could take care of launching the Postgres server in a Testcontainer
> instance, apply DB migrations using Flyway and *then* run the jOOQ code
> gen, once the DB is fully up and "ready" with all the tables/etc in place.)
>
> What does your use case look like more in detail, I guess you run this
> towards a "fixed", existing DB rather than a Docker container? Could you
> share some of your build.gradle to illustrate how you run the code
> generation in this case?
>
> Best regards,
> Per
> ------------------------------
> *From:* [email protected] <[email protected]> on behalf
> of Kevin Jones <[email protected]>
> *Sent:* Monday, July 10, 2023 19:20
> *To:* [email protected] <[email protected]>
> *Subject:* Re: Code Generation Directory
>
> I suppose that looking at examples none of the ones I found for Gradle
> code generation talked about or showed the need to set the base directory
> explicitly. Based on that I assumed the base directory was going to be the
> current project directory, obviously it's not
>
> Kevin
>
> On Mon, Jul 10, 2023 at 2:30 PM Lukas Eder <[email protected]> wrote:
>
> Hi Kevin,
>
> jOOQ's code generator doesn't really know *how* you run it. I'm not a
> Gradle guru myself, but build tools often set base directories in one way
> or another (e.g. where you run the gradle process isn't the same as where
> the project resides, or the parent project in case you have modules, etc.)
> Personally, I never trust my judgement in understanding this behaviour, and
> instead, always use explicit environment variables, system properties or
> other well known variables. So, telling jOOQ explicitly what $projectDir
> means to you, which is a well known, documented variable, does seem quite
> alright, no? Why wouldn't it be?
>
> See:
> https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14F19
>
> Cheers,
> Lukas
>
> On Sat, Jul 8, 2023 at 7:00 PM Kevin Jones <[email protected]>
> wrote:
>
> I've setup JOOQ code generation in Gradle using the Kotlin DSL.
>
>
> The generator works except that I have to use the fully qualified name for
> the output directory, so
>
>
> .withTarget(
> Target()
> .withPackageName("com.knowledgespike.db")
>
> .withDirectory("/users/kevinj/projects/thisproject/src/main/generated/kotlin")
>
> )
>
>
> works, but
>
>
> .withTarget(
> Target()
> .withPackageName("com.knowledgespike.db")
> .withDirectory("src/main/generated/kotlin")
> )
>
>
> doesn't
>
>
> If I set the baseDirectory on the configuration object that also works
> (i.e. I get the code generated relative to the base directory).
>
>
> What I'd like is to get the code generated in my current project directory.
>
>
> I can call .withBasedir("$projectDir") but that doesn't feel right to me.
> Should this "just work"?
>
>
> Thanks,
>
>
> Kevin Jones
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/84785ad5-285c-4ac8-90c9-80658024b233n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/84785ad5-285c-4ac8-90c9-80658024b233n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/CAB4ELO58R1_1Oe%2BxkVAgmtMFrjygwUn_KR8fHWr5d%2BaQhp7yOA%40mail.gmail.com
> <https://groups.google.com/d/msgid/jooq-user/CAB4ELO58R1_1Oe%2BxkVAgmtMFrjygwUn_KR8fHWr5d%2BaQhp7yOA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
>
>
> --
> Kevin Jones
> KnowledgeSpike
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/CAKT%3DYsPOLjT42JcSoiduH%2Bdy4LEd8NOAYg--oBmqFSf1d%2BX4Jg%40mail.gmail.com
> <https://groups.google.com/d/msgid/jooq-user/CAKT%3DYsPOLjT42JcSoiduH%2Bdy4LEd8NOAYg--oBmqFSf1d%2BX4Jg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/VI1PR0801MB1871A10BA262EB3F873E789AEA0BA%40VI1PR0801MB1871.eurprd08.prod.outlook.com
> <https://groups.google.com/d/msgid/jooq-user/VI1PR0801MB1871A10BA262EB3F873E789AEA0BA%40VI1PR0801MB1871.eurprd08.prod.outlook.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Kevin Jones
KnowledgeSpike

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAKT%3DYsNLOJY39Ou%3DZMeF5Mb1Q2oJ5D%2BrZp%3Ds_Lc5Tt7DTTxUxQ%40mail.gmail.com.

Reply via email to