Skip to content

Commit 235a161

Browse files
committed
Reformatted with checkstyle
1 parent 8f87c0a commit 235a161

File tree

13 files changed

+684
-57
lines changed

13 files changed

+684
-57
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# S_BookAPIJAVA
1+
# S_BookAPIJAVA
2+
3+
### Gradle Daemon: Stop the Daemon and Force a Clean Run
4+
5+
**Step 1: Forcefully stop all running Gradle daemons.**
6+
Forcefully stop all running Gradle daemons.
7+
This command tells Gradle to find any background processes it has running and terminate them.
8+
```Bash
9+
./gradlew --stop
10+
```
11+
12+
**Step 2: Run a clean build.**
13+
The clean task deletes the entire build directory. This removes any old, compiled artifacts and cached results, ensuring nothing stale is left over. We will combine it with the checkstyleMain task.
14+
```Bash
15+
./gradlew clean checkstyleMain
16+
```

build.gradle

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@ plugins {
22
id 'java'
33
id 'org.springframework.boot' version '3.5.7'
44
id 'io.spring.dependency-management' version '1.1.7'
5+
6+
// --- Quality Tooling ---
7+
id 'jacoco' // Code coverage
8+
id 'checkstyle' // Style rule enforcement
9+
id 'com.github.spotbugs' version '6.0.7' // Static analysis for bugs
10+
id 'com.diffplug.spotless' version '6.25.0' // Code formatting
511
}
612

713
group = 'com.codesungrape.hmcts'
814
version = '0.0.1-SNAPSHOT'
915
description = 'Demo project for Spring Boot'
1016

1117
java {
18+
// Toolchain is the modern way to define JDK version.
19+
// It automatically handles source/target compatibility.
1220
toolchain {
13-
languageVersion = JavaLanguageVersion.of(21)
14-
}
21+
languageVersion = JavaLanguageVersion.of(21)
22+
}
1523
}
1624

1725
configurations {
@@ -31,11 +39,108 @@ dependencies {
3139
compileOnly 'org.projectlombok:lombok'
3240
runtimeOnly 'org.postgresql:postgresql'
3341
annotationProcessor 'org.projectlombok:lombok'
42+
3443
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3544
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
45+
testImplementation 'com.h2database:h2'
3646
testImplementation 'org.junit.jupiter:junit-jupiter-params'
3747
}
3848

49+
// ===== TESTING & COVERAGE CONFIGURATION =====
50+
3951
tasks.named('test') {
4052
useJUnitPlatform()
53+
finalizedBy jacocoTestReport // Always generate report after tests
54+
55+
// Add this for better test output
56+
testLogging {
57+
events "passed", "skipped", "failed"
58+
exceptionFormat "full"
59+
showStandardStreams = false
60+
}
61+
}
62+
63+
// Configure JaCoCo
64+
jacoco {
65+
toolVersion = '0.8.11'
66+
}
67+
68+
// Generate coverage reports
69+
jacocoTestReport {
70+
dependsOn test
71+
reports {
72+
xml.required = true // For CI systems like SonarQube/Codecov
73+
html.required = true // For human-readable reports
74+
csv.required = false
75+
}
76+
}
77+
78+
// ENFORCE 100% coverage with branch coverage
79+
jacocoTestCoverageVerification {
80+
dependsOn jacocoTestReport
81+
82+
violationRules {
83+
rule {
84+
element = 'CLASS'
85+
86+
// Exclude common classes that don't need testing
87+
excludes = [
88+
'**.*Application', // Spring Boot main class
89+
'**.*ApplicationTests', // Test classes
90+
'**.*Config', // Configuration classes
91+
'**.*Configuration', // Alternative config naming
92+
'**.config.*', // Config package
93+
'**.dto.*', // DTOs
94+
'**.entity.*', // JPA entities
95+
'**.model.*', // Models (if used)
96+
'**.*Constants', // Constant classes
97+
'**.*Exception' // Custom exceptions (optional)
98+
]
99+
limit {
100+
counter = 'INSTRUCTION'
101+
value = 'COVEREDRATIO'
102+
minimum = 1.00 // 100% instruction coverage
103+
}
104+
limit {
105+
counter = 'BRANCH'
106+
value = 'COVEREDRATIO'
107+
minimum = 1.00 // 100% branch coverage (if/else, switch, etc.)
108+
}
109+
}
110+
}
111+
}
112+
113+
// ===== CODE QUALITY & STYLE CONFIGURATION =====
114+
115+
spotless {
116+
java {
117+
googleJavaFormat('1.17.0').aosp() // A popular, opinionated style
118+
removeUnusedImports()
119+
trimTrailingWhitespace()
120+
endWithNewline()
121+
}
122+
}
123+
124+
checkstyle {
125+
toolVersion = '12.1.2'
126+
maxWarnings = 0 // Fail build on any warning
127+
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
128+
}
129+
130+
spotbugs {
131+
// Recommended to use a more recent tool version
132+
toolVersion = '4.8.3'
133+
// Fail the build on any identified issue
134+
ignoreFailures = false
135+
}
136+
137+
138+
// ===== BUILD LIFECYCLE INTEGRATION =====
139+
// The standard 'check' task will now run all quality gates
140+
141+
tasks.named('check') {
142+
dependsOn jacocoTestCoverageVerification
143+
dependsOn tasks.named('spotlessCheck')
144+
dependsOn tasks.named('checkstyleMain')
145+
dependsOn tasks.named('spotbugsMain')
41146
}

0 commit comments

Comments
 (0)