Skip to content

Commit da5750c

Browse files
authored
Port build dependencies to gradle version catalogue (#86548)
We introduce the use of a Gradle version catalogue for handling build related dependencies. This provides type safe accessors for dependencies and allow centralised version definitions. Later we want to move all our dependency handling to version catalogues. Since this is a Gradle feature we remove long term maintenance cost for custom version handling in our build and make centralised version handling more straight forward and support better tooling based on version catalogues Fixes asm version alignment on the way using 9.3 everywhere in our build logic.
1 parent 36fd640 commit da5750c

File tree

7 files changed

+128
-65
lines changed

7 files changed

+128
-65
lines changed

build-conventions/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ repositories {
6262
}
6363

6464
dependencies {
65-
api 'org.apache.maven:maven-model:3.6.2'
66-
api 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
67-
api 'org.apache.rat:apache-rat:0.11'
68-
compileOnly "com.puppycrawl.tools:checkstyle:9.3"
69-
api('com.diffplug.spotless:spotless-plugin-gradle:6.5.2') {
65+
api buildLibs.maven.model
66+
api buildLibs.shadow.plugin
67+
api buildLibs.apache.rat
68+
compileOnly buildLibs.checkstyle
69+
api(buildLibs.spotless.plugin) {
7070
exclude module: "groovy-xml"
7171
}
7272
}

build-conventions/settings.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
* in compliance with, at your election, the Elastic License 2.0 or the Server
66
* Side Public License, v 1.
77
*/
8-
rootProject.name = 'build-conventions'
8+
rootProject.name = 'build-conventions'
9+
10+
dependencyResolutionManagement {
11+
versionCatalogs {
12+
buildLibs {
13+
from(files("../gradle/build.versions.toml"))
14+
}
15+
}
16+
}

build-tools-internal/build.gradle

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -217,79 +217,77 @@ dependencies {
217217
components.all(JacksonAlignmentRule)
218218
constraints {
219219
// ensuring brought asm version brought in by spock is up-to-date
220-
testImplementation 'org.ow2.asm:asm:9.3'
221-
integTestImplementation 'org.ow2.asm:asm:9.3'
220+
testImplementation buildLibs.asm
221+
integTestImplementation buildLibs.asm
222222
}
223223
// Forcefully downgrade the jackson platform as used in production
224-
api enforcedPlatform("com.fasterxml.jackson:jackson-bom:${versions.getProperty('jackson')}")
224+
api enforcedPlatform(buildLibs.jackson.platform)
225225
api localGroovy()
226226
api gradleApi()
227227

228228
api "org.elasticsearch:build-conventions:$version"
229229
api "org.elasticsearch.gradle:build-tools:$version"
230230

231231
// same version as http client transitive dep
232-
api 'commons-codec:commons-codec:1.11'
233-
api 'org.apache.commons:commons-compress:1.21'
234-
api 'org.apache.ant:ant:1.10.8'
235-
api 'com.netflix.nebula:gradle-info-plugin:11.3.3'
236-
api 'org.apache.rat:apache-rat:0.11'
237-
api "net.java.dev.jna:jna:${versions.getProperty('jna')}"
238-
api 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
232+
api buildLibs.commons.codec
233+
api buildLibs.apache.compress
234+
api buildLibs.nebula.info
235+
api buildLibs.apache.rat
236+
api buildLibs.jna
237+
api buildLibs.shadow.plugin
239238
// for our ide tweaking
240-
api 'gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.1'
239+
api buildLibs.idea.ext
241240
// When upgrading forbidden apis, ensure dependency version is bumped in ThirdPartyPrecommitPlugin as well
242-
api 'de.thetaphi:forbiddenapis:3.2'
243-
api 'com.avast.gradle:gradle-docker-compose-plugin:0.14.13'
244-
api 'org.apache.maven:maven-model:3.6.2'
241+
api buildLibs.forbiddenApis
242+
api buildLibs.docker.compose
243+
api buildLibs.maven.model
245244
// needs to match the jackson minor version in use
246-
api 'com.networknt:json-schema-validator:1.0.49'
247-
api "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.getProperty('jackson')}"
248-
api 'org.ow2.asm:asm:9.2'
249-
api 'org.ow2.asm:asm-tree:9.2'
250-
api "org.apache.httpcomponents:httpclient:${versions.getProperty('httpclient')}"
251-
api "org.apache.httpcomponents:httpcore:${versions.getProperty('httpcore')}"
252-
compileOnly "com.puppycrawl.tools:checkstyle:${versions.getProperty('checkstyle')}"
245+
api buildLibs.json.schema.validator
246+
api buildLibs.jackson.dataformat.yaml
247+
api buildLibs.asm
248+
api buildLibs.asm.tree
249+
api buildLibs.httpclient
250+
api buildLibs.httpcore
251+
compileOnly buildLibs.checkstyle
253252
runtimeOnly "org.elasticsearch.gradle:reaper:$version"
254-
testImplementation "com.puppycrawl.tools:checkstyle:${versions.getProperty('checkstyle')}"
255-
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
256-
testImplementation 'org.mockito:mockito-core:1.9.5'
257-
testImplementation "org.hamcrest:hamcrest:${versions.getProperty('hamcrest')}"
258-
253+
testImplementation buildLibs.checkstyle
254+
testImplementation buildLibs.wiremock
255+
testImplementation buildLibs.mockito.core
256+
testImplementation buildLibs.hamcrest
259257
testImplementation testFixtures("org.elasticsearch.gradle:build-tools:$version")
260258

261-
testImplementation(platform("org.junit:junit-bom:${versions.getProperty('junit5')}"))
262-
testImplementation("org.junit.jupiter:junit-jupiter") {
259+
testImplementation(platform(buildLibs.junit5.platform))
260+
testImplementation(buildLibs.junit5.jupiter) {
263261
because 'allows to write and run Jupiter tests'
264262
}
265-
integTestImplementation(platform("org.junit:junit-bom:${versions.getProperty('junit5')}"))
266-
integTestImplementation("org.junit.jupiter:junit-jupiter") {
263+
integTestImplementation(platform(buildLibs.junit5.platform))
264+
integTestImplementation(buildLibs.junit5.jupiter) {
267265
because 'allows to write and run Jupiter tests'
268266
}
269-
integTestImplementation("net.bytebuddy:byte-buddy:1.12.9") {
267+
integTestImplementation(buildLibs.bytebuddy) {
270268
because 'Generating dynamic mocks of internal libraries like JdkJarHell'
271269
}
272-
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
270+
testRuntimeOnly(buildLibs.junit5.vintage) {
273271
because 'allows JUnit 3 and JUnit 4 tests to run'
274272
}
275-
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
273+
testRuntimeOnly(buildLibs.junit5.platform.launcher) {
276274
because 'allows tests to run from IDEs that bundle older version of launcher'
277275
}
278276

279-
testImplementation platform("org.spockframework:spock-bom:2.1-groovy-3.0")
280-
testImplementation("org.spockframework:spock-core") {
277+
testImplementation platform(buildLibs.spock.platform)
278+
testImplementation(buildLibs.spock.core) {
281279
exclude module: "groovy"
282280
}
283-
integTestImplementation platform("org.spockframework:spock-bom:2.1-groovy-3.0")
284-
integTestImplementation("org.spockframework:spock-core") {
281+
integTestImplementation platform(buildLibs.spock.platform)
282+
integTestImplementation(buildLibs.spock.core) {
285283
exclude module: "groovy"
286284
}
287285
// required as we rely on junit4 rules
288-
integTestImplementation("org.spockframework:spock-junit4") {
286+
integTestImplementation(buildLibs.spock.junit4) {
289287
exclude module: "groovy"
290288
}
291-
testImplementation "org.spockframework:spock-junit4"
292-
integTestImplementation "org.xmlunit:xmlunit-core:2.8.2"
289+
testImplementation buildLibs.spock.junit4
290+
integTestImplementation buildLibs.xmlunit.core
293291
}
294292

295293
tasks.named('test').configure {

build-tools-internal/settings.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencyResolutionManagement {
2+
versionCatalogs {
3+
buildLibs {
4+
from(files("../gradle/build.versions.toml"))
5+
}
6+
}
7+
}

build-tools/build.gradle

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,42 +106,42 @@ repositories {
106106
dependencies {
107107
constraints {
108108
// ensuring brought asm version brought in by spock is up-to-date
109-
testFixturesApi 'org.ow2.asm:asm:9.3'
110-
integTestImplementation 'org.ow2.asm:asm:9.3'
109+
testFixturesApi buildLibs.asm
110+
integTestImplementation buildLibs.asm
111111
}
112112
reaper project('reaper')
113113

114114
api localGroovy()
115115
api gradleApi()
116-
api 'org.apache.commons:commons-compress:1.21'
117-
api 'org.apache.ant:ant:1.10.8'
118-
api 'commons-io:commons-io:2.2'
119-
implementation 'org.ow2.asm:asm-tree:9.3'
120-
implementation 'org.ow2.asm:asm:9.3'
121-
122-
testFixturesApi "junit:junit:${versions.getProperty('junit')}"
123-
testFixturesApi "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.getProperty('randomizedrunner')}"
116+
api buildLibs.apache.compress
117+
api buildLibs.ant
118+
api buildLibs.commmons.io
119+
implementation buildLibs.asm.tree
120+
implementation buildLibs.asm
121+
124122
testFixturesApi gradleApi()
125123
testFixturesApi gradleTestKit()
126-
testFixturesApi 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
127-
testFixturesApi platform("org.spockframework:spock-bom:2.1-groovy-3.0")
128-
testFixturesApi("org.spockframework:spock-core") {
124+
testFixturesApi buildLibs.junit
125+
testFixturesApi buildLibs.randomized.runner
126+
testFixturesApi buildLibs.wiremock
127+
testFixturesApi platform(buildLibs.spock.platform)
128+
testFixturesApi(buildLibs.spock.core) {
129129
exclude module: "groovy"
130130
}
131131

132-
integTestImplementation("org.spockframework:spock-junit4") {
132+
integTestImplementation(buildLibs.spock.junit4) {
133133
because 'required as we rely on junit4 rules'
134134
}
135135

136-
integTestImplementation(platform("org.junit:junit-bom:${versions.getProperty('junit5')}"))
137-
integTestImplementation("org.junit.jupiter:junit-jupiter") {
136+
integTestImplementation(platform(buildLibs.junit5.platform))
137+
integTestImplementation(buildLibs.junit5.jupiter) {
138138
because 'allows to write and run Jupiter tests'
139139
}
140-
integTestRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
140+
integTestRuntimeOnly(buildLibs.junit5.vintage) {
141141
because 'allows JUnit 3 and JUnit 4 tests to run'
142142
}
143143

144-
integTestRuntimeOnly("org.junit.platform:junit-platform-launcher") {
144+
integTestRuntimeOnly(buildLibs.junit5.platform.launcher) {
145145
because 'allows tests to run from IDEs that bundle older version of launcher'
146146
}
147147
}

build-tools/settings.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
* in compliance with, at your election, the Elastic License 2.0 or the Server
66
* Side Public License, v 1.
77
*/
8-
include 'reaper'
8+
include 'reaper'
9+
10+
dependencyResolutionManagement {
11+
versionCatalogs {
12+
buildLibs {
13+
from(files("../gradle/build.versions.toml"))
14+
}
15+
}
16+
}

gradle/build.versions.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[versions]
2+
asm = "9.3"
3+
jackson = "2.13.2"
4+
junit5 = "5.8.1"
5+
spock = "2.1-groovy-3.0"
6+
7+
[libraries]
8+
ant = "org.apache.ant:ant:1.10.8"
9+
apache-compress = "org.apache.commons:commons-compress:1.21"
10+
apache-rat = "org.apache.rat:apache-rat:0.11"
11+
asm = { group = "org.ow2.asm", name="asm", version.ref="asm" }
12+
asm-tree = { group = "org.ow2.asm", name="asm-tree", version.ref="asm" }
13+
bytebuddy = "net.bytebuddy:byte-buddy:1.12.9"
14+
checkstyle = "com.puppycrawl.tools:checkstyle:9.3"
15+
commons-codec = "commons-codec:commons-codec:1.11"
16+
commmons-io = "commons-io:commons-io:2.2"
17+
docker-compose = "com.avast.gradle:gradle-docker-compose-plugin:0.14.13"
18+
forbiddenApis = "de.thetaphi:forbiddenapis:3.2"
19+
hamcrest = "org.hamcrest:hamcrest:2.1"
20+
httpcore = "org.apache.httpcomponents:httpcore:4.4.12"
21+
httpclient = "org.apache.httpcomponents:httpclient:4.5.10"
22+
idea-ext = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.1"
23+
json-schema-validator = "com.networknt:json-schema-validator:1.0.49"
24+
jackson-dataformat-yaml = { group = "com.fasterxml.jackson.dataformat", name="jackson-dataformat-yaml", version.ref="jackson" }
25+
jackson-platform = { group = "com.fasterxml.jackson", name="jackson-bom", version.ref="jackson" }
26+
jna = "net.java.dev.jna:jna:5.10.0"
27+
junit = "junit:junit:4.12"
28+
junit5-platform = { group = "org.junit", name="junit-bom", version.ref="junit5" }
29+
junit5-jupiter = { group = "org.junit.jupiter", name="junit-jupiter", version.ref="junit5" }
30+
junit5-platform-launcher = "org.junit.platform:junit-platform-launcher:1.8.0"
31+
junit5-vintage = { group = "org.junit.vintage", name="junit-vintage-engine", version.ref="junit5" }
32+
maven-model = "org.apache.maven:maven-model:3.6.2"
33+
mockito-core = "org.mockito:mockito-core:1.9.5"
34+
nebula-info = "com.netflix.nebula:gradle-info-plugin:11.3.3"
35+
randomized-runner = "com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.7"
36+
shadow-plugin = "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"
37+
spock-core = { group = "org.spockframework", name="spock-core", version.ref="spock" }
38+
spock-junit4 = { group = "org.spockframework", name="spock-junit4", version.ref="spock" }
39+
spock-platform = { group = "org.spockframework", name="spock-bom", version.ref="spock" }
40+
spotless-plugin = "com.diffplug.spotless:spotless-plugin-gradle:6.5.2"
41+
wiremock = "com.github.tomakehurst:wiremock-jre8-standalone:2.23.2"
42+
xmlunit-core = "org.xmlunit:xmlunit-core:2.8.2"

0 commit comments

Comments
 (0)