175 lines
5.5 KiB
Kotlin
175 lines
5.5 KiB
Kotlin
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
|
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
|
import java.sql.DriverManager
|
|
|
|
plugins {
|
|
id("org.springframework.boot") version "3.2.5"
|
|
id("io.spring.dependency-management") version "1.1.4"
|
|
id("org.openapi.generator") version "7.4.0"
|
|
id("nu.studer.jooq") version "9.0"
|
|
id("application")
|
|
id("java")
|
|
}
|
|
|
|
val postgresqlVersion: String by project
|
|
val flywayVersion: String by project
|
|
val jooqVersion: String by project
|
|
val logbackVersion: String by project
|
|
|
|
group = "net.moustos"
|
|
version = "0.1.0"
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
|
implementation("org.springframework.boot:spring-boot-starter-security")
|
|
implementation("org.springframework.boot:spring-boot-starter-validation")
|
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
|
|
|
implementation("org.postgresql:postgresql:$postgresqlVersion")
|
|
implementation("org.flywaydb:flyway-core:$flywayVersion")
|
|
|
|
implementation("org.jooq:jooq:$jooqVersion")
|
|
implementation("org.jooq:jooq-meta:$jooqVersion")
|
|
implementation("org.jooq:jooq-codegen:$jooqVersion")
|
|
jooqGenerator("org.postgresql:postgresql:$postgresqlVersion")
|
|
|
|
implementation("com.auth0:java-jwt:4.4.0")
|
|
implementation("org.springframework.security:spring-security-crypto:6.2.3")
|
|
|
|
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0")
|
|
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1")
|
|
|
|
implementation("ch.qos.logback:logback-core:$logbackVersion")
|
|
implementation("ch.qos.logback:logback-classic:$logbackVersion")
|
|
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
|
|
|
compileOnly("org.projectlombok:lombok:1.18.30")
|
|
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
|
|
|
implementation("org.apache.commons:commons-lang3:3.14.0")
|
|
implementation("com.google.guava:guava:33.1.0-jre")
|
|
|
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
testImplementation("org.springframework.security:spring-security-test")
|
|
testImplementation("org.testcontainers:testcontainers:1.19.7")
|
|
testImplementation("org.testcontainers:postgresql:1.19.7")
|
|
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
|
|
testImplementation("org.mockito:mockito-core:5.7.1")
|
|
testImplementation("org.mockito:mockito-junit-jupiter:5.7.1")
|
|
testImplementation("io.rest-assured:rest-assured:5.4.0")
|
|
}
|
|
|
|
java {
|
|
toolchain {
|
|
languageVersion.set(JavaLanguageVersion.of(21))
|
|
}
|
|
}
|
|
|
|
application {
|
|
mainClass.set("net.moustos.mtgsearch.MtgSearchApplication")
|
|
}
|
|
|
|
springBoot {
|
|
buildInfo()
|
|
}
|
|
|
|
openApiGenerate {
|
|
generatorName.set("spring")
|
|
inputSpec.set("$projectDir/openapi/api.yaml")
|
|
outputDir.set("$projectDir/build/generated")
|
|
apiPackage.set("net.moustos.mtgsearch.api")
|
|
modelPackage.set("net.moustos.mtgsearch.model.api")
|
|
globalProperties.set(mapOf(
|
|
"apis" to "true",
|
|
"models" to "true"
|
|
))
|
|
configOptions.set(mapOf(
|
|
"delegatePattern" to "true",
|
|
"title" to "MTG Search API",
|
|
"interfaceOnly" to "false",
|
|
"skipDefaultInterface" to "false",
|
|
"useSpringBoot3" to "true",
|
|
"useJakartaEe" to "true"
|
|
))
|
|
}
|
|
|
|
jooq {
|
|
configurations {
|
|
create("main") {
|
|
jooqConfiguration.apply {
|
|
jdbc.apply {
|
|
driver = "org.postgresql.Driver"
|
|
url = project.property("db.url") as String
|
|
user = project.property("db.user") as String
|
|
password = project.property("db.password") as String
|
|
}
|
|
generator.apply {
|
|
name = "org.jooq.codegen.JavaGenerator"
|
|
database.apply {
|
|
name = "org.jooq.meta.postgres.PostgresDatabase"
|
|
inputSchema = "public"
|
|
}
|
|
target.apply {
|
|
packageName = "net.moustos.mtgsearch.jooq.generated"
|
|
directory = "$projectDir/build/generated/jooq"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fun isPostgresAvailable(): Boolean {
|
|
return try {
|
|
DriverManager.setLoginTimeout(2)
|
|
DriverManager.getConnection(project.property("db.url") as String, project.property("db.user") as String, project.property("db.password") as String).use { true }
|
|
} catch (ex: Exception) {
|
|
logger.warn("PostgreSQL is unavailable at configured DB; skipping jOOQ code generation.")
|
|
false
|
|
}
|
|
}
|
|
|
|
tasks.named("generateJooq") {
|
|
onlyIf {
|
|
isPostgresAvailable()
|
|
}
|
|
doFirst {
|
|
logger.lifecycle("Starting jOOQ code generation...")
|
|
}
|
|
doLast {
|
|
logger.lifecycle("Finished jOOQ task.")
|
|
}
|
|
}
|
|
|
|
tasks.named("compileJava") {
|
|
dependsOn("openApiGenerate")
|
|
}
|
|
|
|
sourceSets["main"].java {
|
|
srcDir("$buildDir/generated/src/main/java")
|
|
srcDir("$buildDir/generated/jooq")
|
|
}
|
|
|
|
tasks.withType<JavaCompile> {
|
|
options.encoding = "UTF-8"
|
|
options.compilerArgs.add("-parameters")
|
|
}
|
|
|
|
tasks.withType<Test> {
|
|
useJUnitPlatform()
|
|
testLogging {
|
|
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
|
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
|
showStandardStreams = false
|
|
}
|
|
}
|
|
|
|
tasks.named("build") {
|
|
dependsOn("openApiGenerate")
|
|
}
|