我需要配置gradle构建文件的jOOQ与Testcontainers和Flyway的示例,在jOOQ的官方存储库中,我只找到maven示例,无法将其转换为gradle,我尝试自己转换,但得到了这个:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// test container
classpath "org.testcontainers:postgresql:$testContainersVersion"
}
}
plugins {
id 'java'
id 'nu.studer.jooq' version "$jooqPluginVersion"
id "org.flywaydb.flyway" version "$flywayPluginVersion"
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
// postgres
runtimeOnly 'org.postgresql:postgresql'
// jooq
jooqGenerator "org.postgresql:postgresql:$postgresVersion"
// flyway
implementation 'org.flywaydb:flyway-core'
// tests
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.testcontainers:testcontainers:$testContainersVersion"
testImplementation "org.testcontainers:postgresql:$testContainersVersion"
}
var JdbcDatabaseContainer<?> postgres = new PostgreSQLContainerProvider().newInstance("14-alpine")
postgres.start()
flyway {
url = postgres.jdbcUrl
user = postgres.username
password = postgres.password
schemas = ['public']
locations = ['classpath:db/migration']
baselineOnMigrate = true
}
tasks {
doLast {
if (postgres.isRunning) {
println("STOPPING DATABASE CONTAINER")
postgres.stop()
}
}
}
jooq {
version = "$jookVersion" // default (can be omitted)
edition = JooqEdition.OSS // default (can be omitted)
configurations {
main { // name of the jOOQ configuration
generateSchemaSourceOnCompilation = true // default (can be omitted)
generationTool {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
url = postgres.jdbcUrl
user = postgres.username
password = postgres.password
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
forcedTypes {
forcedType {
userType = 'com.fasterxml.jackson.databind.JsonNode'
includeTypes = '.*'
includeExpression = '.*JSON.*'
binding = 'dataflow.binding.PostgresJSONBBinding'
}
}
}
generate {
pojosAsKotlinDataClasses = true
deprecated = false
records = true
pojos = true
immutablePojos = false
fluentSetters = true
daos = true
}
target {
packageName = "dataflow.$dataflowPackageName"
directory = 'build/generated-src/jooq/main' // default (can be omitted)
}
strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy'
}
}
}
}
}
它创建了三个容器,而不是一个,并且不停止它们。另外,我使用Gradle jOOQ plugin
2条答案
按热度按时间4si2a6ki1#
我最近遇到了类似的mysql,gradle,flyway和jooq的案例。基于gradle-jooq-plugin(https://github.com/etiennestuder/gradle-jooq-plugin/blob/master/example/)的例子,我为我的案例提出了可行的解决方案,只需稍作修改,它也应该适用于您的案例:
fykwrbwg2#
我们使用下面的流程(它是Kotlin,只包含脚本中与JOOQ资源相关的部分)。与this answer的主要区别是,我的流程在你只运行
generateJooq
任务时会启动一个新容器。另一个流程在每个任务中都会运行一个新容器。