Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jOOQ Gradle plugin does not update generated files

Tags:

java

gradle

jooq

For some reason I have to manually delete generated folder and run gradle task to get updated POJOs. Is this my setup, expected behavior or a bug? My setup is as follows:

jooq {
  library(sourceSets.main) {
    jdbc {
      driver = 'com.mysql.jdbc.Driver'
      url = 'jdbc:mysql://localhost:3306/library'
      user = 'library'
      password = '123'
      schema = 'library'
    }
    generator {
      name = 'org.jooq.util.DefaultGenerator'
      strategy {
        name = 'org.jooq.util.DefaultGeneratorStrategy'
      }
      database {
        name = 'org.jooq.util.mysql.MySQLDatabase'
        inputSchema = 'library'
      }
      generate {
        daos = true
      }
      target {
        packageName = 'com.example.library.db'
        directory = 'src/main/java'
      }
    }
  }
}
like image 317
Schultz9999 Avatar asked Oct 19 '22 23:10

Schultz9999


1 Answers

Currently when you generated the files they're added under src/main/java folder. This is not a good idea since you have mixed source and generated files. It's much better to add a separate folder src/main/generated and modify the build.gradle in the following way:

def generatedDir = 'src/main/generated'
sourceSets {
    main {
        java {
            srcDirs += [generatedDir]
        }
    }
}

clean.doLast {
   project.file(generatedDir).deleteDir()
}

and change:

target {
   packageName = 'com.example.library.db'
   directory = generatedDir
}

This way you can easily manage the generated classes. All the classes will be removed automatically when clean task is run.

You also need to define a dependency between compileJava and the generator task. It can be done in the following way:

compileJava.dependsOn YOUR_GENERATOR_TASK_NAME

jOOQ will not delete the files automatically.

like image 65
Opal Avatar answered Oct 26 '22 23:10

Opal