import nu.studer.gradle.jooq.JooqEdition
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.utility.ResourceReaper
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// testcontainers
classpath "org.testcontainers:postgresql:$testContainersVersion"
}
}
/*
* Plugins
*/
plugins {
id 'java'
id 'org.springframework.boot' version "$springBootPluginVersion"
id 'io.spring.dependency-management' version "$springDependencyManagerPluginVersion"
id "org.jetbrains.kotlin.jvm" version "$kotlinJvmPluginVersion"
id "org.jetbrains.kotlin.plugin.spring" version "$kotlinJvmPluginVersion"
id "com.google.protobuf" version "$protobufPluginVersion"
id 'nu.studer.jooq' version "$jooqPluginVersion"
id 'maven-publish'
id 'jacoco'
id "org.flywaydb.flyway" version "$flywayPluginVersion"
id "org.jetbrains.kotlin.kapt" version "$kaptPluginVersion"
id "com.dorongold.task-tree" version "2.1.0"
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
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'
// our libs
if (System.env.GITLAB_CI) {
implementation fileTree(dir: '.', include: ['*.jar'])
} else {
implementation project(':lib-commons')
implementation project(':lib-project-constructor')
implementation project(':lib-module-library')
implementation project(':lib-config-constructor')
implementation project(':lib-data-accessor')
}
// 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"
}
/**
* Database
*/
tasks.register("tcStart") {
var db = new PostgreSQLContainer("postgres:14-alpine")
.withUsername("postgres")
.withDatabaseName("postgres")
.withPassword("postgres")
db.start()
println("Starting container: ${db.containerId}")
project.ext.db_url = db.jdbcUrl
project.ext.container_id = db.containerId
project.ext.image_name = db.dockerImageName
project.ext['flyway.url'] = db.jdbcUrl
project.ext['jooq.configuration.jdbc.url'] = db.jdbcUrl
project.ext['jooq.configurations.main.jdbc.url'] = db.jdbcUrl
}
tasks.register("tcStop") {
var containerId = project.ext.container_id
var imageName = project.ext.image_name
println("Stopping container: $containerId")
ResourceReaper
.instance()
.stopAndRemoveContainer(containerId, imageName);
}
flyway {
// url = "jdbc:postgresql://$dbHost:$dbPort/$dbName?currentSchema=public&ApplicationName=$dbApplication"
user = 'postgres'
password = 'postgres'
schemas = ['public']
locations = ['classpath:db/migration']
baselineOnMigrate = true
}
/*
* jOOQ configuration
*/
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.DEBUG
jdbc {
driver = 'org.postgresql.Driver'
// set url from test container
url = project.ext.db_url
user = 'postgres'
password = 'postgres'
}
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'
}
}
}
}
}
flywayMigrate.dependsOn tcStart
generateJooq.dependsOn flywayMigrate
//test.dependsOn tcStop