我有这个Gradle脚本用于自动生成JOOQ类.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(
'org.jooq:jooq:3.18.4',
'org.jooq:jooq-codegen:3.18.4',
'org.jooq:jooq-meta:3.18.4',
'org.postgresql:postgresql:42.6.0'
)
}
}
apply plugin: 'java'
apply plugin: 'nu.studer.jooq'
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.*
task generateJooq {
def configuration = new Configuration()
.withJdbc(
new Jdbc()
.withDriver('org.postgresql.Driver')
.withUrl('jdbc:postgresql://localhost:5432/test')
.withUser('postgres')
.withPassword('password'))
.withGenerator(
new Generator()
.withDatabase(new Database().withExcludes("databasechangeloglock|databasechangelog").withInputSchema("public"))
.withGenerate(
new Generate()
.withRoutines(false)
.withPojos(true)
.withDaos(true)
).withTarget(
new Target()
.withPackageName('com.example.model.jooq')
.withDirectory(projectDir.toString() + '/src/main/java')
).withStrategy(
new Strategy()
.withMatchers(
new Matchers()
.withTables(
new MatchersTableType()
.withTableIdentifier(
new MatcherRule()
.withExpression('$0_Entity')
.withTransform(MatcherTransformType.UPPER)
).withPojoClass(new MatcherRule().withExpression('$0_Entity').withTransform(MatcherTransformType.PASCAL))
)
)
)
)
doLast {
GenerationTool.generate(configuration)
}
}
但是,当我对表进行任何更改(例如,进行迁移)时,我需要更改我的POJO、记录等类.当我运行任务generateJooq
时,它会删除所有类并重新创建它们的类和problem is that all the lombok annotations (data, builder) disappear.
我希望在运行任务时,JOOQ将只重新创建更改的表,如果不重新创建甚至更好,并且只在现有类中添加新的字段.