-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
262 lines (211 loc) · 9.1 KB
/
build.gradle
File metadata and controls
262 lines (211 loc) · 9.1 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
plugins {
id 'java'
id 'org.springframework.boot' version '4.0.5'
// Use Spring AOT
// https://docs.spring.io/spring-boot/gradle-plugin/aot.html
id 'org.springframework.boot.aot' version '4.0.5'
id 'io.freefair.lombok' version '9.2.0'
id 'me.qoomon.git-versioning' version '6.4.4'
// Generating a git.properties file containing information about the state of your git source code repository when the project was built
// https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.build.generate-git-info
// https://github.com/n0mer/gradle-git-properties
id 'com.gorylenko.gradle-git-properties' version '2.5.4'
// https://github.com/ben-manes/gradle-versions-plugin
// Provides tasks for discovering dependency updates.
id 'com.github.ben-manes.versions' version '0.53.0'
// a Gradle plugin used to generate Java code for Windows APIs. It leverages the Java Foreign Function & Memory (FFM) API
//id("net.codecrete.windows-api") version "0.8.3"
}
apply plugin: 'io.spring.dependency-management'
group = 'by.rayden'
version = '0.0.0'
gitVersioning.apply {
// https://github.com/qoomon/gradle-git-versioning-plugin
describeTagPattern = 'v.+'
refs {
considerTagsOnBranches = true
branch('master') {
version = '${describe.tag.version}-${commit.short}'
properties_["appExtProperty"] = '${commit.timestamp.year}-${commit.timestamp.month}-${commit.timestamp.day} ${commit.timestamp.hour}:${commit.timestamp.minute}:${commit.timestamp.second}'
}
branch('(?<branch>.+)') {
version = '${describe.tag.version}-${ref.branch.slug}-${commit.short}'
properties_["appExtProperty"] = '${commit.timestamp.year}-${commit.timestamp.month}-${commit.timestamp.day} ${commit.timestamp.hour}:${commit.timestamp.minute}:${commit.timestamp.second}'
}
}
rev {
version = "\${commit.short}"
}
}
gitProperties {
extProperty = 'gitProps' // git properties will be put in a map at project.ext.gitProps
// fine-grained control of the content of git.properties
keys = [
'git.branch',
'git.build.version',
'git.closest.tag.commit.count',
'git.closest.tag.name',
'git.commit.id',
'git.commit.id.abbrev',
'git.commit.id.describe',
'git.commit.time',
'git.dirty',
'git.tags',
'git.total.commit.count'
]
}
generateGitProperties.outputs.upToDateWhen { false } // make sure the generateGitProperties task always executes (even when git.properties is not changed)
bootJar {
// Locking the file name to avoid changing it every time in cmd-scripts
archiveFileName = 'ParaCoder.jar'
// a script variable to capture the result of using project.ext to calculate the actual parameter
// https://docs.gradle.org/8.12.1/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
def my_project_ext = project.ext
manifest {
// Filling the manifest attribute using the git property.
attributes 'Build-Revision': "${-> my_project_ext.gitProps['git.commit.id.abbrev']}" // Use GString lazy evaluation to delay until git properties are populated
attributes 'Enable-Native-Access': 'ALL-UNNAMED'
}
}
springBoot {
// https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.build.generate-info
// https://docs.spring.io/spring-boot/docs/3.2.3/gradle-plugin/reference/htmlsingle/#integrating-with-actuator.build-info
// This will configure a BuildInfo task named bootBuildInfo.
// A BuildInfo task is provided to generate " "build/resources/main/META-INF/build-info.properties"
buildInfo()
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(26)
}
}
repositories {
mavenCentral()
}
configurations {
mockitoAgent
}
configurations.configureEach {
// https://gradlehero.com/how-to-exclude-gradle-dependencies/
exclude group: 'io.micrometer'
}
// Override the dependencies versions managed by Spring Boot.
// See https://docs.spring.io/spring-boot/appendix/dependency-versions/properties.html#appendix.dependency-versions.properties
// Override the JUnit version.
// See https://docs.junit.org/current/user-guide/#running-tests-build-spring-boot
ext['junit-jupiter.version'] = '6.0.3'
// Override the LogBack version.
// Fix CVE-2025-11226. See https://www.mend.io/vulnerability-database/CVE-2025-11226
// Fix CVE-2026-1225. See https://www.cvedetails.com/cve/CVE-2026-1225/
ext['logback.version'] = '1.5.32'
// Override the Mockito version.
ext['mockito.version'] = '5.23.0'
ext['mockito-junit-jupiter.version'] = '5.23.0'
dependencies {
compileOnly 'org.jetbrains:annotations:26.1.0'
implementation 'info.picocli:picocli-spring-boot-starter:4.7.7'
implementation 'org.fusesource.jansi:jansi:2.4.3'
implementation 'commons-io:commons-io:2.21.0'
implementation 'org.digitalmediaserver:cuelib-core:2.0.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core'
mockitoAgent('org.mockito:mockito-core') {
transitive = false
}
}
lombok {
version = '1.18.44'
}
// See https://docs.spring.io/spring-boot/gradle-plugin/reacting.html point 11.
// Spring Boot plugin already Configures any JavaCompile tasks with no configured encoding to use UTF-8.
//tasks.withType(JavaCompile).configureEach {
// // https://gist.github.com/rponte/d660919434d094bbd35a1aabf7ef1bf0
// // https://docs.spring.io/spring-boot/docs/3.2.2/gradle-plugin/reference/htmlsingle/#reacting-to-other-plugins.java
// options.encoding = "UTF-8"
//}
tasks.withType(Test).configureEach {
defaultCharacterEncoding = "UTF-8"
}
tasks.withType(Javadoc).configureEach {
options.encoding = "UTF-8"
}
tasks.register('versionDebug') {
def my_project = project
doLast {
println(my_project.version)
println(my_project.property("appExtProperty"))
println(my_project.property("git.commit"))
println(my_project.property("git.commit.timestamp.datetime"))
println(my_project.property("git.ref"))
}
}
tasks.register('prepareAotLayout', JavaExec) {
group = "build"
description = 'Prepare the extracted application for AOT Cache creation'
dependsOn tasks.bootJar
def sourceJar = bootJar.archiveFile.get().asFile
def extractDir = layout.buildDirectory.dir("libs\\extracted").get().asFile
doFirst {
delete extractDir
}
// Setup for SpringBoot command "jarmode=tools":
// java -Djarmode=tools -jar d:\java\prj\paracoder\build\libs\ParaCoder.jar extract --destination d:\java\prj\paracoder\build\libs\extracted
jvmArgs = ["-Djarmode=tools"]
mainClass = "-jar" // A trick that allows to run a JAR directly by passing its path in args
args = [
sourceJar.absolutePath,
"extract",
"--destination", extractDir.absolutePath
]
// Tell Gradle that we are creating a directory (for incremental builds)
outputs.dir(extractDir)
}
tasks.register('generateAotCache', JavaExec) {
group = 'build'
description = 'Generates AOT Cache for the Java application'
dependsOn tasks.prepareAotLayout, tasks.processAot
// Dynamically get the launcher from the project's toolchain settings to ensure
// that javac (compilation) and java (cache generation in the generateAotCache task)
// use the same JDK binary file.
def service = project.extensions.getByType(JavaToolchainService)
javaLauncher = service.launcherFor(java.toolchain)
// Setting up a training run:
def extractDir = layout.buildDirectory.dir("libs\\extracted").get().asFile
workingDir = extractDir
mainClass = "-jar"
// Training run using thin (extracted) JAR (must end with code 0).
// The CLI must do minimal work and shut down to save the cache, so use '--help' parameter
def thinJar = file("${extractDir}\\${bootJar.archiveFileName.get()}")
args = [
thinJar.absolutePath,
'--help'
]
// Java AOT-Cache write options
jvmArgs = [
"-XX:AOTCacheOutput=${layout.buildDirectory.get()}\\libs\\paracoder.aot",
"-XX:+UseCompactObjectHeaders",
"-Dspring.aot.enabled=true",
"-Dspring.context.exit=onRefresh"
]
}
tasks.named('build') {
dependsOn 'processAot'
}
// Link "generateAotCache" task to the build cycle: the cache will be created immediately after the "build"
tasks.named('build') {
finalizedBy 'generateAotCache'
}
test {
useJUnitPlatform()
// to suppress WARNING like this:
// "A Java agent has been loaded dynamically... byte-buddy-agent...",
// "OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes
// because bootstrap classpath has been appended"
jvmArgs += '--enable-native-access=ALL-UNNAMED'
jvmArgs += '-Xshare:off'
jvmArgs += "-javaagent:${configurations.mockitoAgent.asPath}"
// To show passed test in console output
// testLogging {
// events "passed", "skipped", "failed" // , "standardOut", "standardError"
// }
}