Refactor build.gradle with centralized version management and improved test configuration
All checks were successful
continuous-integration/drone/push Build is passing
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:
103
build.gradle
103
build.gradle
@ -1,17 +1,31 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '3.3.4'
|
id 'org.springframework.boot' version '3.3.3'
|
||||||
id 'io.spring.dependency-management' version '1.1.6'
|
id 'io.spring.dependency-management' version '1.1.5'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'se.urmo'
|
group = 'se.urmo'
|
||||||
version = '0.0.1-SNAPSHOT'
|
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 {
|
dependencies {
|
||||||
// --- Spring starters ---
|
// --- Spring starters ---
|
||||||
@ -20,54 +34,71 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
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-oauth2-resource-server'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
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
|
// --- OpenAPI (Swagger UI) ---
|
||||||
implementation 'org.flywaydb:flyway-core'
|
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdocVersion}"
|
||||||
implementation 'org.flywaydb:flyway-database-postgresql'
|
|
||||||
|
|
||||||
// DB driver
|
// --- DB / migrations ---
|
||||||
runtimeOnly 'org.postgresql:postgresql:42.7.4'
|
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) ---
|
// --- Lombok ---
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.32'
|
compileOnly "org.projectlombok:lombok:${lombokVersion}"
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
|
||||||
testCompileOnly 'org.projectlombok:lombok:1.18.32'
|
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
|
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
|
||||||
|
|
||||||
// --- Tests ---
|
// --- Test ---
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
testImplementation 'org.springframework.security:spring-security-test'
|
testImplementation 'org.springframework.security:spring-security-test'
|
||||||
testImplementation 'com.jayway.jsonpath:json-path:2.9.0'
|
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()
|
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 {
|
finalizedBy tasks.jacocoTestReport
|
||||||
dependsOn test
|
}
|
||||||
|
|
||||||
|
jacoco {
|
||||||
|
toolVersion = "0.8.10"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.jacocoTestReport {
|
||||||
|
dependsOn tasks.test
|
||||||
reports {
|
reports {
|
||||||
xml.required = true
|
xml.required = true // useful for CI
|
||||||
html.required = true
|
html.required = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jacocoTestCoverageVerification {
|
tasks.bootJar {
|
||||||
violationRules {
|
// if you later add a versioning scheme, you can also inject build info here
|
||||||
rule {
|
archiveFileName = "hemhub-api.jar"
|
||||||
limit {
|
|
||||||
counter = 'LINE'
|
|
||||||
value = 'COVEREDRATIO'
|
|
||||||
minimum = 0.65 // börja rimligt (65%), höj senare
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check.dependsOn jacocoTestCoverageVerification
|
tasks.jar {
|
||||||
|
enabled = false // Spring Boot builds fat jar via bootJar
|
||||||
tasks.test { useJUnitPlatform() }
|
}
|
||||||
|
|||||||
4
gradle.properties
Normal file
4
gradle.properties
Normal 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
|
||||||
Reference in New Issue
Block a user