通过liquibasedatabase生成JOOQ时如何使用Postgres数据库
有很好的指南如何使用liquibase
我的解决方案(build.gradle.kts):
plugins {
java
id("nu.studer.jooq") version "7.1.1"
id("org.liquibase.gradle") version "2.1.1"
}
java {
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
}
dependencies {
jooqGenerator("org.postgresql:postgresql:42.3.2")
jooqGenerator("org.slf4j:slf4j-jdk14:1.7.30")
jooqGenerator("org.testcontainers:postgresql:1.17.1")
liquibaseRuntime(files("src/main/resources"))
liquibaseRuntime("org.testcontainers:postgresql:1.17.1")
liquibaseRuntime("org.postgresql:postgresql:42.3.2")
liquibaseRuntime("org.liquibase:liquibase-core")
liquibaseRuntime("info.picocli:picocli:4.6.1")
liquibaseRuntime("ch.qos.logback:logback-core:1.2.3")
liquibaseRuntime(sourceSets.getByName("main").compileClasspath)
liquibaseRuntime(sourceSets.getByName("main").output)
}
liquibase {
activities.register("main") {
this.arguments = mapOf(
"logLevel" to "info",
"changeLogFile" to "db/migration/changelog-master.xml",
"url" to "jdbc:tc:postgresql:9.6.8:///postgres?TC_DAEMON=true",
"username" to "user",
"password" to "password",
"driver" to "org.testcontainers.jdbc.ContainerDatabaseDriver"
)
}
runList = "main"
}
tasks.withType<JooqGenerate> {
dependsOn(tasks.named("update"))
}
jooq {
version.set("3.16.6")
edition.set(nu.studer.gradle.jooq.JooqEdition.OSS)
configurations {
create("main") {
generateSchemaSourceOnCompilation.set(true)
jooqConfiguration.apply {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc.apply {
driver = "org.testcontainers.jdbc.ContainerDatabaseDriver"
url = "jdbc:tc:postgresql:9.6.8:///postgres?TC_DAEMON=true"
user = "user"
password = "password"
}
generator.apply {
name = "org.jooq.codegen.DefaultGenerator"
database.apply {
name = "org.jooq.meta.postgres.PostgresDatabase"
inputSchema = "public"
}
generate.apply {
isDeprecated = false
isRecords = true
isImmutablePojos = true
isFluentSetters = true
}
target.apply {
packageName = "com.example"
directory = "build/generated-src/jooq/main"
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
}
}
}
}
}
tasks.named<nu.studer.gradle.jooq.JooqGenerate>("generateJooq") {
(launcher::set)(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(18))
})
}
期望:
after running code gen ./gradlew generateJooq first starts postgres testcontainer and liquibase apply migrations, after that starts jooq code generation现实:
after running code gen starts postgres testcontainer and liquibase apply migrations and then starts new testcontainer and jooq tries generate records是否有任何解决方案可以为迁移和代码gen指定一个Postgres容器?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案:
(build.gradle.kts)
./gradlew清洁更新构建
Solution:
(build.gradle.kts)
./gradlew clean update build
在官方JOOQ博客上,他们为
文章继续进行,并描述如何使用Jooq用作现代方法,使用TestContainers ,这可能有助于可能有助于有助于了解使用JOOQ的LiquiBasedAtabase命令的适当程序。
这是一些其他文档:
On the official jOOQ blog, they wrote up a guide for Using Testcontainers to Generate jOOQ Code
The article continues, and describes how you can use jOOQ as a Modern Approach Using Testcontainers, which may help with understanding the proper procedures for using jOOQ's LiquibaseDatabase command.
Here is some additional documentation: