200 lines
6.6 KiB
Kotlin
200 lines
6.6 KiB
Kotlin
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
|
import java.util.Properties
|
|
import java.io.File
|
|
|
|
plugins {
|
|
id("java")
|
|
id("org.springframework.boot") version "4.0.+" apply false
|
|
id("io.spring.dependency-management") version "1.1.6"
|
|
id("org.sonarqube") version "7.2.3.7755"
|
|
}
|
|
|
|
sonar {
|
|
properties {
|
|
property("sonar.projectKey", "MTGSearch")
|
|
property("sonar.projectName", "MTGSearch")
|
|
property("sonar.qualitygate.wait", true)
|
|
}
|
|
}
|
|
|
|
group = "net.moustos"
|
|
version = "0.1.0"
|
|
|
|
// Load dev.properties if it exists
|
|
val devPropsFile = File("dev.properties")
|
|
val devProps = Properties().apply {
|
|
if (devPropsFile.exists()) {
|
|
load(devPropsFile.inputStream())
|
|
}
|
|
}
|
|
|
|
// Define properties with defaults, preferring env vars over dev.properties
|
|
val propertiesMap = mapOf(
|
|
"db.url" to (System.getenv("DB_URL") ?: devProps.getProperty("db.url", "jdbc:postgresql://localhost:5432/mtgsearch")),
|
|
"db.user" to (System.getenv("DB_USER") ?: devProps.getProperty("db.user", "postgres")),
|
|
"db.password" to (System.getenv("DB_PASSWORD") ?: devProps.getProperty("db.password", "postgres")),
|
|
"db.maxPoolSize" to (System.getenv("DB_MAX_POOL_SIZE") ?: devProps.getProperty("db.maxPoolSize", "10")),
|
|
"jwt.secret" to (System.getenv("JWT_SECRET") ?: devProps.getProperty("jwt.secret", "your-secret-key-change-in-production")),
|
|
"jwt.expiration" to (System.getenv("JWT_EXPIRATION") ?: devProps.getProperty("jwt.expiration", "86400")),
|
|
"app.name" to (System.getenv("APP_NAME") ?: devProps.getProperty("app.name", "mtg-search")),
|
|
"app.version" to (System.getenv("APP_VERSION") ?: devProps.getProperty("app.version", "0.1.0")),
|
|
"app.environment" to (System.getenv("APP_ENVIRONMENT") ?: devProps.getProperty("app.environment", "development")),
|
|
"server.port" to (System.getenv("SERVER_PORT") ?: devProps.getProperty("server.port", "8080")),
|
|
"server.servlet.contextPath" to (System.getenv("SERVER_SERVLET_CONTEXT_PATH") ?: devProps.getProperty("server.servlet.contextPath", "/")),
|
|
"vite.apiUrl" to (System.getenv("VITE_API_URL") ?: devProps.getProperty("vite.apiUrl", "http://localhost:8080")),
|
|
"vite.appTitle" to (System.getenv("VITE_APP_TITLE") ?: devProps.getProperty("vite.appTitle", "MTG Search")),
|
|
"log.level" to (System.getenv("LOG_LEVEL") ?: devProps.getProperty("log.level", "DEBUG")),
|
|
"log.dir" to (System.getenv("LOG_DIR") ?: devProps.getProperty("log.dir", "logs"))
|
|
)
|
|
|
|
// Set system properties for Spring Boot
|
|
propertiesMap.forEach { (key, value) ->
|
|
System.setProperty(key, value)
|
|
}
|
|
|
|
// Also set as project extra for Gradle use
|
|
propertiesMap.forEach { (key, value) ->
|
|
extra.set(key, value)
|
|
}
|
|
|
|
allprojects {
|
|
repositories {
|
|
mavenCentral()
|
|
maven {
|
|
url = uri("https://repo.maven.apache.org/maven2/")
|
|
}
|
|
}
|
|
}
|
|
|
|
configure(subprojects.filter { it.name == "backend" }) {
|
|
apply(plugin = "java")
|
|
|
|
java {
|
|
sourceCompatibility = JavaVersion.VERSION_21
|
|
targetCompatibility = JavaVersion.VERSION_21
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
// Developer helper tasks
|
|
tasks.register("createDevProperties") {
|
|
group = "developer"
|
|
description = "Creates dev.properties file with default values if it doesn't exist"
|
|
|
|
doLast {
|
|
val devPropsFile = File("dev.properties")
|
|
if (!devPropsFile.exists()) {
|
|
val defaultContent = """
|
|
# Development properties
|
|
# This file contains configuration values for build and runtime.
|
|
# Do not commit this file to the repository.
|
|
|
|
# Database Configuration
|
|
db.url=jdbc:postgresql://localhost:5432/mtgsearch
|
|
db.user=postgres
|
|
db.password=postgres
|
|
db.maxPoolSize=10
|
|
|
|
# JWT Configuration
|
|
jwt.secret=your-secret-key-change-in-production
|
|
jwt.expiration=86400
|
|
|
|
# Application Configuration
|
|
app.name=mtg-search
|
|
app.version=0.1.0
|
|
app.environment=development
|
|
|
|
# Server Configuration
|
|
server.port=8080
|
|
server.servlet.contextPath=/
|
|
|
|
# Frontend Configuration
|
|
vite.apiUrl=http://localhost:8080
|
|
vite.appTitle=MTG Search
|
|
|
|
# Logging
|
|
log.level=DEBUG
|
|
log.dir=logs
|
|
""".trimIndent()
|
|
devPropsFile.writeText(defaultContent)
|
|
println("Created dev.properties with default values")
|
|
} else {
|
|
println("dev.properties already exists")
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.register<Exec>("startPostgres") {
|
|
group = "developer"
|
|
description = "Starts the PostgreSQL container using docker-compose"
|
|
|
|
doFirst {
|
|
// Check if Docker is available
|
|
val dockerCheck = providers.exec {
|
|
commandLine("docker", "info")
|
|
isIgnoreExitValue = true
|
|
}
|
|
if (dockerCheck.result.get().exitValue != 0) {
|
|
throw GradleException("""
|
|
Docker is not available or not running. Please ensure:
|
|
1. Docker daemon is running
|
|
2. You have permission to access Docker (try 'sudo usermod -aG docker ${'$'}USER' and restart your session)
|
|
3. Docker Compose is installed
|
|
""".trimIndent())
|
|
}
|
|
println("Starting PostgreSQL container...")
|
|
}
|
|
|
|
commandLine("docker", "compose", "up", "-d", "postgres")
|
|
workingDir = project.rootDir
|
|
|
|
doLast {
|
|
println("PostgreSQL container started. Waiting for it to be healthy...")
|
|
// Optional: wait for health check
|
|
Thread.sleep(5000) // Simple wait, could be improved
|
|
println("PostgreSQL should be ready now.")
|
|
}
|
|
}
|
|
|
|
tasks.register<Exec>("stopPostgres") {
|
|
group = "developer"
|
|
description = "Stops the PostgreSQL container using docker-compose"
|
|
|
|
doFirst {
|
|
// Check if Docker is available
|
|
val dockerCheck = providers.exec {
|
|
commandLine("docker", "info")
|
|
isIgnoreExitValue = true
|
|
}
|
|
if (dockerCheck.result.get().exitValue != 0) {
|
|
throw GradleException("""
|
|
Docker is not available or not running. Please ensure:
|
|
1. Docker daemon is running
|
|
2. You have permission to access Docker (try 'sudo usermod -aG docker ${'$'}USER' and restart your session)
|
|
3. Docker Compose is installed
|
|
""".trimIndent())
|
|
}
|
|
println("Stopping PostgreSQL container...")
|
|
}
|
|
|
|
commandLine("docker", "compose", "down")
|
|
workingDir = project.rootDir
|
|
|
|
doLast {
|
|
println("PostgreSQL container stopped.")
|
|
}
|
|
}
|