-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathbuild.gradle
More file actions
363 lines (328 loc) · 11.7 KB
/
Copy pathbuild.gradle
File metadata and controls
363 lines (328 loc) · 11.7 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration
plugins {
alias(libs.plugins.spotless)
alias(libs.plugins.docker)
}
tasks.register("compileAll") {
group = "build"
description = "Compiles all Java and Kotlin sources, including tests, across all projects."
}
// to allow to have unused vars/imports,etc for faster debugging/prototyping
// instead of deleting and re-adding code all the time
def allowCompilationWarnings = System.getenv('LINEA_DEV_ALLOW_WARNINGS') != null
spotless {
predeclareDeps()
}
spotlessPredeclare {
groovyGradle {
greclipse("4.35")
}
java {
removeUnusedImports()
googleJavaFormat(libs.versions.googleJavaFormat.get())
}
kotlin {
ktlint(libs.versions.ktlint.get().toString())
.editorConfigOverride([
'ktlint_standard_discouraged-comment-location': 'disabled',
'ktlint_standard_property-naming': 'disabled',
'ktlint_standard_function-naming': 'disabled',
'ktlint_standard_function-signature': 'disabled',
])
}
}
allprojects {
// Aggregate every Java/Kotlin compile task (main + tests, all source sets) into root :compileAll.
afterEvaluate { proj ->
proj.tasks.withType(JavaCompile).all { compileTask ->
rootProject.tasks.named("compileAll").configure { dependsOn(compileTask) }
}
proj.tasks.withType(KotlinCompile).all { compileTask ->
rootProject.tasks.named("compileAll").configure { dependsOn(compileTask) }
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'java' // do not add kotlin plugin here, it will add unnecessary Kotlin runtime dependencies
apply plugin: 'jacoco'
// Override JUnit version from Besu BOM to ensure Java 25 compatibility
configurations.configureEach { cfg ->
resolutionStrategy.eachDependency { details ->
if (details.requested.group in [
'org.junit.platform',
'org.junit.jupiter',
'org.junit'
]) {
def junitVersion = details.requested.group == 'org.junit.platform' ?
"${libs.versions.junitPlatform.get()}" : "${libs.versions.junit.get()}"
details.useVersion(junitVersion)
details.because('Java 25 requires JUnit 5.13+ for ASM compatibility')
}
if (!cfg.name.toLowerCase().contains('spotless')
&& !cfg.name.toLowerCase().contains('ktlint')
&& details.requested.group in [
'org.hyperledger.besu',
'org.hyperledger.besu.internal'
] &&
(!details.requested.version || details.requested.version.trim().isEmpty())) {
details.useVersion(rootProject.ext.resolveBesuVersion())
details.because('Versionless Besu dependencies are aligned to the lazily resolved Besu version') // e.g. jvm-libs:linea:besu-libs
}
}
}
tasks.withType(KotlinCompile).configureEach {
compilerOptions {
allWarningsAsErrors = !allowCompilationWarnings
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.deprecation = true
options.compilerArgs.addAll([
'-parameters',
'-Xlint:cast',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Xlint:deprecation',
'-Xlint:unchecked',
'-Xlint:rawtypes',
'-Werror'
])
if (allowCompilationWarnings) {
options.compilerArgs.remove('-Werror')
}
if (project.path.contains("testing-tools")) {
// testing tools have 100+ errors because of this
// skipping them for now
options.compilerArgs.remove('-Xlint:rawtypes')
}
}
jacoco {
toolVersion = libs.versions.jacoco.get()
if (project.tasks.findByName('integrationTest')) {
applyTo integrationTest
}
if (project.tasks.findByName('acceptanceTest')) {
applyTo acceptanceTest
}
if (project.tasks.findByName('acceptanceTests')) {
applyTo acceptanceTests
}
}
jacocoTestReport {
dependsOn test
}
tasks.withType(Javadoc).configureEach {
exclude '**/generated/**'
}
tasks.withType(Test).configureEach {
testLogging {
events = [
//TestLogEvent.STARTED,
//TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR
]
exceptionFormat TestExceptionFormat.FULL
showCauses true
showExceptions true
showStackTraces true
// set showStandardStreams if you need to see test logs
showStandardStreams false
}
systemProperty("L1_RPC_URL", "http://localhost:8445")
systemProperty("L2_RPC_URL", "http://localhost:8545")
systemProperty("L1_GENESIS", "docker/config/l1-node/el/genesis.json")
systemProperty("L2_GENESIS", "docker/config/linea-local-dev-genesis-PoA-besu.json")
systemProperties["junit.jupiter.execution.timeout.default"] = "5 m" // 5 minutes
systemProperties["junit.jupiter.execution.parallel.enabled"] = true
systemProperties["junit.jupiter.execution.parallel.mode.default"] = "concurrent"
systemProperties["junit.jupiter.execution.parallel.mode.classes.default"] = "concurrent"
maxParallelForks = Math.max(Runtime.runtime.availableProcessors(), 9)
}
tasks.withType(Test).matching { it.name == 'integrationTest' }.configureEach {
outputs.cacheIf { false }
outputs.upToDateWhen { false }
}
afterEvaluate { subproject ->
if (hasJavaOrKotlinPlugins(subproject)) {
subproject.apply plugin: 'com.diffplug.spotless'
subproject.spotless {
if (hasKotlinPlugin(subproject)) {
kotlin {
// by default the target is every '.kt' and '.kts` file in the java sourcesets
//ktfmt()
ktlint(libs.versions.ktlint.get().toString())
.editorConfigOverride([
'ktlint_standard_discouraged-comment-location': 'disabled',
'ktlint_standard_property-naming': 'disabled',
'ktlint_standard_function-naming': 'disabled',
'ktlint_standard_function-signature': 'disabled',
// 'ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than': '1'
])
}
}
// spotless check applied to build.gradle (groovy) files
groovyGradle {
target '*.gradle'
greclipse("4.35")
leadingTabsToSpaces(2)
endWithNewline()
}
java {
target 'src/**/*.java'
// Do not use 'targetExclude' with wildcard patterns, it will add minutes to the build
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
googleJavaFormat(libs.versions.googleJavaFormat.get())
}
// Below this line are currently only license header tasks
// format 'groovy', { target '**/src/*/groovy/**/*.groovy' }
// format 'bash', { target '**/*.sh' }
// format 'sol', { target '**/*.sol' }
}
}
}
}
task jacocoRootReport(type: JacocoReport) {
// Define a project list will all subprojects excluding 'tracer' (TODO: fix to include tracer)
def reportProjects = subprojects.findAll { subproject ->
// Get the path of the subproject relative to the root dir (e.g., "tracer/lib-a")
def relativePath = rootProject.relativePath(subproject.projectDir)
// Include only if the path does NOT start with "tracer"
return !relativePath.startsWith('tracer')
}
additionalSourceDirs.from files(reportProjects.sourceSets.main.allSource.srcDirs)
sourceDirectories.from files(reportProjects.sourceSets.main.allSource.srcDirs)
classDirectories.from files(reportProjects.sourceSets.main.output)
// Exclude the tracer folder from the execution data scan (TODO: fix to include tracer)
executionData.from fileTree(dir: '.', includes: ['**/jacoco/*.exec'], excludes: ['tracer/**'])
reports {
xml.required = true
// xml.enabled = true FIXME: deprecated, breaking latest versions of gradle.
csv.required = true
html.outputLocation = file("build/reports/jacocoHtml")
}
onlyIf = { true }
}
dockerCompose {
localStack {
startedServices = [
"postgres",
"sequencer",
"maru",
"l1-node-genesis-generator",
"l2-genesis-initialization",
"l1-el-node",
"l1-cl-node",
// For debug
// "l1-blockscout",
// "l2-blockscout"
]
composeAdditionalArgs = [
"--profile",
"l1",
"--profile",
"l2"
]
useComposeFiles = [
"${project.rootDir.path}/docker/compose-tracing-v2.yml"
]
waitForHealthyStateTimeout = Duration.ofMinutes(3)
waitForTcpPorts = false
stopContainers = false
removeOrphans = true
// this is to avoid recreating the containers
// specially l1-node-genesis-generator which corrupts the state if run more than once
// without cleaning the volumes
noRecreate = true
projectName = "docker"
}
localStackPostgresDbOnly {
startedServices = ["postgres"]
useComposeFiles = [
"${project.rootDir.path}/docker/compose-tracing-v2.yml"
]
waitForHealthyStateTimeout = Duration.ofMinutes(3)
stopContainers = false
waitForTcpPorts = true
removeOrphans = true
noRecreate = true
projectName = "docker"
}
localStackForStateRecovery {
startedServices = [
"postgres",
"sequencer",
"l1-node-genesis-generator",
"l1-el-node",
"l1-cl-node",
"blobscan-api",
"blobscan-indexer",
"redis",
]
composeAdditionalArgs = [
"--profile",
"l1",
"--profile",
"l2",
"--profile",
"staterecovery"
]
useComposeFiles = [
"${project.rootDir.path}/docker/compose-tracing-v2-staterecovery-extension.yml"
]
waitForHealthyStateTimeout = Duration.ofMinutes(3)
waitForTcpPorts = false
removeOrphans = true
stopContainers = false
// this is to avoid recreating the containers
// specially l1-node-genesis-generator which corrupts the state if run more than once
// without cleaning the volumes
noRecreate = true
projectName = "docker"
}
}
// Pull only the images required by `startedServices` of the `localStack` compose stack.
// Useful in CI to retry the (sometimes flaky) Docker Hub pull in isolation, without
// rerunning the integration test.
tasks.register("composePullLocalStackStartedImages", Exec) {
group = 'docker'
description = "Pull only the startedServices images for the 'localStack' compose stack."
workingDir rootDir
doFirst {
def settings = dockerCompose.localStack
def fileArgs = settings.useComposeFiles.get().collectMany { ['-f', it.toString()] }
def additionalArgs = settings.composeAdditionalArgs.get()
def services = settings.startedServices.get()
commandLine(['docker', 'compose'] + fileArgs + additionalArgs + ['pull'] + services)
}
}
// Seed the gitignored runtime deny-list before any compose-up so the sequencer's
// bind-mount finds a regular file (not an auto-created directory) on fresh checkouts.
// Delegates to the Makefile target so Make and Gradle stay in lockstep.
def seedSequencerDenyList = tasks.register("seedSequencerDenyList", Exec) {
workingDir rootDir
commandLine 'make', 'seed-deny-list'
}
tasks.matching { it.name.endsWith("ComposeUp") }.configureEach {
dependsOn(seedSequencerDenyList)
}
static Boolean hasKotlinPlugin(Project proj) {
return proj.plugins.hasPlugin("org.jetbrains.kotlin.jvm")
}
static Boolean hasJavaPlugin(Project proj) {
return (proj.plugins.hasPlugin("java") || proj.plugins.hasPlugin("java-library"))
}
static Boolean hasJavaOrKotlinPlugins(Project proj) {
return (hasKotlinPlugin(proj) || hasJavaPlugin(proj))
}