Refactor build.gradle with centralized version management and improved test configuration
All checks were successful
continuous-integration/drone/push Build is passing

Centralized dependency versions into `ext` block for easier upgrades. Enhanced test task with parallel execution, fail-fast behavior, and improved logging. Updated JaCoCo settings, introduced `gradle.properties` for build optimizations, and adjusted `bootJar`/`jar` tasks for cleaner outputs.
This commit is contained in:
Urban Modig
2025-10-08 18:08:08 +02:00
parent 54b70d9494
commit acb1c841b0
2 changed files with 71 additions and 36 deletions

View File

@ -1,17 +1,31 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.5'
id 'jacoco'
}
group = 'se.urmo'
version = '0.0.1-SNAPSHOT'
java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }
repositories { mavenCentral() }
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
ext['flyway.version'] = '10.17.3' // managed override
repositories {
mavenCentral()
}
ext {
// Pin Flyway to a PG16-compatible version that aligns with Spring Boot 3.3.x
set('flyway.version', '10.17.3')
lombokVersion = '1.18.32'
springdocVersion = '2.6.0'
h2Version = '2.2.224'
pgJdbcVersion = '42.7.4'
}
dependencies {
// --- Spring starters ---
@ -20,54 +34,71 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Core Flyway + Postgres driver plugin
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-database-postgresql'
// --- OpenAPI (Swagger UI) ---
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdocVersion}"
// DB driver
runtimeOnly 'org.postgresql:postgresql:42.7.4'
// --- DB / migrations ---
runtimeOnly "org.postgresql:postgresql:${pgJdbcVersion}"
implementation 'org.flywaydb:flyway-core' // version from ext.flyway.version
implementation 'org.flywaydb:flyway-database-postgresql' // PG support module
// --- Lombok (used in services/guards) ---
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'
testCompileOnly 'org.projectlombok:lombok:1.18.32'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
// --- Lombok ---
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
// --- Tests ---
// --- Test ---
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'com.jayway.jsonpath:json-path:2.9.0'
testRuntimeOnly 'com.h2database:h2:2.2.224' // for application-test.yml profile
testRuntimeOnly "com.h2database:h2:${h2Version}" // used by application-test.yml
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 21
}
test {
tasks.test {
useJUnitPlatform()
finalizedBy jacocoTestReport
// ⚡ parallelize tests a bit without overloading CI runners
def cores = Runtime.runtime.availableProcessors()
maxParallelForks = Math.max(1, (int)(cores / 2))
// Fail fast to shorten CI feedback on red builds
failFast = true
testLogging {
events "FAILED", "SKIPPED"
exceptionFormat "short"
showCauses true
showExceptions true
}
jacocoTestReport {
dependsOn test
finalizedBy tasks.jacocoTestReport
}
jacoco {
toolVersion = "0.8.10"
}
tasks.jacocoTestReport {
dependsOn tasks.test
reports {
xml.required = true
xml.required = true // useful for CI
html.required = true
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.65 // börja rimligt (65%), höj senare
}
}
}
tasks.bootJar {
// if you later add a versioning scheme, you can also inject build info here
archiveFileName = "hemhub-api.jar"
}
check.dependsOn jacocoTestCoverageVerification
tasks.test { useJUnitPlatform() }
tasks.jar {
enabled = false // Spring Boot builds fat jar via bootJar
}

4
gradle.properties Normal file
View File

@ -0,0 +1,4 @@
org.gradle.configuration-cache=true
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8