forked from hmcts/api-dcs-crime-caseadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
235 lines (205 loc) · 6.81 KB
/
build.gradle
File metadata and controls
235 lines (205 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
plugins {
id 'java'
id 'org.openapi.generator' version '7.14.0'
id 'com.diffplug.spotless' version '7.0.4'
id 'jacoco'
id 'maven-publish'
id "com.github.ben-manes.versions" version "0.52.0"
id "org.cyclonedx.bom" version "2.3.1"
}
group = 'uk.gov.hmcts.dcs'
version = System.getProperty('API_SPEC_VERSION') ?: '0.0.999'
def githubActor = project.findProperty("github.actor") ?: System.getenv("GITHUB_ACTOR")
def githubToken = project.findProperty("github.token") ?: System.getenv("GITHUB_TOKEN")
def githubRepo = System.getenv("GITHUB_REPOSITORY")
def azureADOArtifactRepository = 'https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1'
def azureADOArtifactActor = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME")
def azureADOArtifactToken = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN")
def formatterUrl = 'https://raw.githubusercontent.com/hmcts/api-cp-code-style/refs/heads/main/config/formatter/eclipse-formatter.xml'
def formatterPath = "${layout.buildDirectory.get().asFile.absolutePath}/eclipse-formatter.xml"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
openApiGenerate {
generatorName = "java"
inputSpec = "${rootDir}/src/main/resources/openapi/dcs-caseadmin.openapi.yml"
outputDir = "${layout.buildDirectory.get().asFile.absolutePath}/generated/sources/openapi"
modelPackage = "uk.gov.hmcts.dcs.openapi.model"
// Configuration options for the Java generator
configOptions = [
library: "native", // Use native Java library
dateLibrary: "java8", // Use Java 8 time API
hideGenerationTimestamp: "true",
//Ensure Jackson is used
serializationLibrary: "jackson",
useJakartaEe: "false", // To avoid Jakarta EE dependencies
sourceFolder: "src/main/java",
generateApis: "false", // Generate only models
generateApiTests: "false",
generateModelTests: "false",
generateSupportingFiles: "false",
]
}
sourceSets {
main {
java {
srcDir "${layout.buildDirectory.get().asFile.absolutePath}/generated/sources/openapi/src/main/java"
}
}
}
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-core:2.19.1' // Use a compatible version
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.19.1' // For Java 8 date/time
implementation 'org.slf4j:slf4j-api:2.0.17'
implementation 'ch.qos.logback:logback-classic:1.5.18'
//If you use the validation, also add this
implementation 'io.swagger.parser.v3:swagger-parser:2.1.30'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.34'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
testImplementation(platform('org.junit:junit-bom:5.13.2'))
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs = ["-Xlint:unchecked", "-Werror"]
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
}
}
tasks.named('test') {
useJUnitPlatform()
systemProperty 'API_SPEC_VERSION', System.getProperty('API_SPEC_VERSION', '0.0.0')
failFast = true
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStandardStreams = true
}
}
tasks.named('jacocoTestReport') {
dependsOn tasks.named('test')
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
}
tasks.named('check') {
dependsOn tasks.named('jacocoTestReport')
}
// check dependencies upon release ONLY
tasks.named("dependencyUpdates").configure {
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { qualifier -> version.toUpperCase().contains(qualifier) }
def regex = /^[0-9,.v-]+$/
return !stableKeyword && !(version ==~ regex)
}
rejectVersionIf {
isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = azureADOArtifactRepository
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/$githubRepo")
credentials {
username = githubActor
password = githubToken
}
}
maven {
name = "AzureArtifacts"
url = uri(azureADOArtifactRepository)
credentials {
username = azureADOArtifactActor
password = azureADOArtifactToken
}
}
}
}
//Creation of Software Bill of Materials
//https://github.com/CycloneDX/cyclonedx-gradle-plugin
cyclonedxBom {
projectType = "library" // or application
includeConfigs = ["runtimeClasspath"]
skipConfigs = ["test", "testImplementation"]
schemaVersion = "1.6"
componentVersion = providers.provider { project.version.toString() }
destination = file("${layout.buildDirectory.get().asFile.absolutePath}/reports")
includeBuildSystem = true
outputName = "bom"
outputFormat = "json"
}
jar {
dependsOn tasks.named('cyclonedxBom')
if (file("CHANGELOG.md").exists()) {
println "✅ Including CHANGELOG.md in JAR"
from('CHANGELOG.md') {
into 'META-INF'
}
} else {
println "⚠️ CHANGELOG.md not found, skipping inclusion in JAR"
}
def sbomFile = file("${layout.buildDirectory.get().asFile.absolutePath}/reports/bom.json")
if (sbomFile.exists()) {
println "✅ Including SBOM from ${sbomFile} in JAR"
from(sbomFile) {
into 'META-INF/sbom'
rename { 'bom.json' }
}
} else {
println "⚠️ SBOM (bom.json) not found, skipping inclusion in JAR"
}
}
spotless {
java {
target 'build/generated/sources/openapi/src/main/**/*.java'
removeUnusedImports()
eclipse().configFile(formatterPath)
}
}
tasks.named('compileJava') {
dependsOn tasks.named('spotlessApply')
}
tasks.named("openApiGenerate") {
inputs.file("${rootDir}/src/main/resources/openapi/dcs-caseadmin.openapi.yml")
}
tasks.named('spotlessApply') {
dependsOn tasks.named('openApiGenerate'), tasks.named('downloadFormatter')
}
tasks.named('spotlessJava') {
dependsOn tasks.named('openApiGenerate'), tasks.named('downloadFormatter')
}
tasks.register('downloadFormatter') {
outputs.file(formatterPath)
doLast {
def file = new File(formatterPath)
file.parentFile.mkdirs()
file.text = new URI(formatterUrl).toURL().text
}
}
tasks.withType(Checkstyle).configureEach {
def generatedDir = file("${layout.buildDirectory.get().asFile.absolutePath}/generated/sources/openapi/src/main/java").canonicalPath
source = source.filter { file ->
!file.canonicalPath.startsWith(generatedDir)
}
}