简体   繁体   中英

JOOQ Code Generation Before Source Code Compilation

I am using JOOQ code generation Tool for generating source code for my schema(MYSQL). I would like to generate source code every time I compile my Project. But I am not able to do it because when I run Code generation gradle Task, Compiler starts complaining about references of deleted source code.

Here is what I did:-

  1. Created an Empty Spring boot Project.
  2. Generated Source code using config xml(jooq.xml below) like this
  3. Triggered Code Generation using a Gradle Task.

Build.gradle

task generateJooqDatabaseSource(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'org.jooq.util.GenerationTool'
    args = ['/jooq.xml']
    standardOutput = System.out
    errorOutput = System.err
}
  1. Used the generated source code and wrote SQLs using JOOQ.

Everything is fine till here. But now I don't want to Push the generated Java Classes to my Project. I would like it to create every time when I compile my Project.

  1. so lets delete the generated source code and re-generate it again(say for my Test environment)

  2. But as soon as I run the Gradle Task generateJooqDatabaseSource
    it starts complaining about the generated code references.

error: package autogenered.jooq.code.db.tables does not exist

import autogenered.jooq.code.db.tables.Author;

Tried googling the problem and found suggestions to use plugins like flyway , suggested here

But I really don't want to add another plugin if it can be achieved easily without it.

PS:- Just started to use Gradle, JOOQ from couple of days, apologies if answer is obvious.

Adding Following Lines in build.gradle have done the tweak for me:

compileJava.dependsOn(generateJooqDatabaseSource)
generateJooqDatabaseSource.dependsOn = [processResources, processTestResources]

Intellij Specific configuration:-

Added gradle build task to be triggered every time I do

make Project (Ctrl-F9)

or

Re-build Project:

IntelliJ Gradle构建任务

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