buildscript {
    dependencies {
        classpath 'com.h2database:h2:2.3.230'
    }
}

plugins {
    id 'java-library'
    id 'org.springframework.boot' version '3.3.2'
    id 'io.spring.dependency-management' version '1.1.6'
    id 'org.flywaydb.flyway' version '10.15.2'
    id "org.jooq.jooq-codegen-gradle" version "3.19.10"
}

ext {
    set('jooq.version', '3.19.7')
}

apply from: "../build.common.gradle"

bootJar {
    enabled = false
}

dependencies {
    runtimeOnly 'com.h2database:h2'
    implementation 'org.flywaydb:flyway-core'
    implementation 'org.springframework.boot:spring-boot-starter-jooq'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

flyway {
    url = "jdbc:h2:file:${projectDir}/build/test-gradle"
    user = 'sa'
    password = 'sa'
}

jooq {
    configuration {
        jdbc {
            driver = 'org.h2.Driver'
            url = "jdbc:h2:file:${projectDir}/build/test-gradle"
            user = 'sa'
            password = 'sa'
        }
        generator {
            database {
                name = 'org.jooq.meta.h2.H2Database'
                inputSchema = 'PUBLIC'
                excludes = """
					flyway_schema_history
					"""
            }
            target {
                packageName = 'dev.abarmin.jooq.db'
                directory = 'src/main/java'
            }
        }
    }
}

tasks.named("jooqCodegen") {
    dependsOn("flywayMigrate")
}