Skip to content

Commit 386869a

Browse files
authored
make gradle files ready for gradle 10 (#17947)
while we're not looking to upgrade immediately to 9 or 10 it's best that .gradle files follow the most modern idioms and practices. This both removes any limitations when we want to upgrade, and also removes warnings regarding deprecations. Also upgrades gradle to the latest 8.x version (8.14.3).
1 parent 895cfa5 commit 386869a

File tree

9 files changed

+114
-76
lines changed

9 files changed

+114
-76
lines changed

build.gradle

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buildscript {
2525
repositories {
2626
mavenCentral()
2727
maven {
28-
url 'https://plugins.gradle.org/m2/'
28+
url = 'https://plugins.gradle.org/m2/'
2929
}
3030
}
3131
}
@@ -103,16 +103,16 @@ allprojects {
103103
testLogging {
104104
// set options for log level LIFECYCLE
105105
events "passed", "skipped", "failed", "standardOut"
106-
showExceptions true
107-
exceptionFormat "full"
108-
showCauses true
109-
showStackTraces true
110-
enableAssertions false
106+
showExceptions = true
107+
exceptionFormat = "full"
108+
showCauses = true
109+
showStackTraces = true
110+
enableAssertions = false
111111

112112
// set options for log level DEBUG and INFO
113113
debug {
114114
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
115-
exceptionFormat "full"
115+
exceptionFormat = "full"
116116
}
117117
info.events = debug.events
118118
info.exceptionFormat = debug.exceptionFormat
@@ -133,7 +133,7 @@ subprojects {
133133
repositories {
134134
mavenCentral()
135135
maven {
136-
url 'https://plugins.gradle.org/m2/'
136+
url = 'https://plugins.gradle.org/m2/'
137137
}
138138
}
139139

@@ -165,8 +165,9 @@ tasks.register("configureArchitecture") {
165165

166166
tasks.register("configureArtifactInfo") {
167167
dependsOn configureArchitecture
168-
description "Set the url to download stack artifacts for select stack version"
168+
description = "Set the url to download stack artifacts for select stack version"
169169

170+
def projectRef = project
170171
doLast {
171172
def splitVersion = version.split('\\.')
172173
int major = splitVersion[0].toInteger()
@@ -189,28 +190,28 @@ tasks.register("configureArtifactInfo") {
189190
}
190191
}
191192

192-
project.ext.set("artifactApiVersion", qualifiedVersion)
193+
projectRef.ext.set("artifactApiVersion", qualifiedVersion)
193194
}
194195
}
195196

196197
tasks.register("markAliasDefinitions", SignAliasDefinitions) {
197-
description "Create an hashes aliases file from original aliases yml definition"
198+
description = "Create an hashes aliases file from original aliases yml definition"
198199
hashedFile = project.file("${project.buildDir}/plugin_aliases_hashed.yml")
199200
}
200201

201202
tasks.register("markTestAliasDefinitions", SignAliasDefinitions) {
202-
description "Create an hashes aliases file for testing aliases yml definition"
203+
description = "Create an hashes aliases file for testing aliases yml definition"
203204
stage SignAliasDefinitions.Stage.test
204205
hashedFile = project.file("${project.buildDir}/plugin_aliases_hashed_test.yml")
205206
}
206207

207208
tasks.register("copyPluginAlias", Copy) {
208-
description "Copy the marked plugin_aliases.yml file to destination folders"
209+
description = "Copy the marked plugin_aliases.yml file to destination folders"
209210
dependsOn = [copyPluginAlias_ruby, copyPluginAlias_java]
210211
}
211212

212213
tasks.register("copyPluginAlias_ruby", Copy) {
213-
description "Copy the marked plugin_aliases.yml file to destination folders"
214+
description = "Copy the marked plugin_aliases.yml file to destination folders"
214215
dependsOn "markAliasDefinitions"
215216

216217
inputs.file("${buildDir}/plugin_aliases_hashed.yml")
@@ -222,7 +223,7 @@ tasks.register("copyPluginAlias_ruby", Copy) {
222223
}
223224

224225
tasks.register("copyPluginAlias_java", Copy) {
225-
description "Copy the marked plugin_aliases.yml file to destination folders"
226+
description = "Copy the marked plugin_aliases.yml file to destination folders"
226227
dependsOn "markAliasDefinitions"
227228

228229
inputs.file("${buildDir}/plugin_aliases_hashed.yml")
@@ -234,12 +235,12 @@ tasks.register("copyPluginAlias_java", Copy) {
234235
}
235236

236237
tasks.register("copyPluginTestAlias") {
237-
description "Copy the marked test plugin_aliases.yml file to destination folders"
238+
description = "Copy the marked test plugin_aliases.yml file to destination folders"
238239
dependsOn = [copyPluginTestAlias_ruby, copyPluginTestAlias_java]
239240
}
240241

241242
tasks.register("copyPluginTestAlias_ruby", Copy) {
242-
description "Copy the marked test plugin_aliases.yml file into Ruby's plugin_manager specs"
243+
description = "Copy the marked test plugin_aliases.yml file into Ruby's plugin_manager specs"
243244
dependsOn "markTestAliasDefinitions"
244245

245246
inputs.file(markTestAliasDefinitions.hashedFile)
@@ -251,7 +252,7 @@ tasks.register("copyPluginTestAlias_ruby", Copy) {
251252
}
252253

253254
tasks.register("copyPluginTestAlias_java", Copy) {
254-
description "Copy the marked test plugin_aliases.yml file into logstash-core's test resources"
255+
description = "Copy the marked test plugin_aliases.yml file into logstash-core's test resources"
255256
dependsOn "markTestAliasDefinitions"
256257

257258
inputs.file("${buildDir}/plugin_aliases_hashed_test.yml")
@@ -447,30 +448,39 @@ tasks.register("installIntegrationTestGems") {
447448
}
448449
}
449450

450-
tasks.register("downloadFilebeat") {
451-
dependsOn configureArtifactInfo
452-
description "Download Filebeat Snapshot for current branch version: ${version}"
451+
tasks.register("prepareFilebeatDownload") {
452+
dependsOn configureArtifactInfo
453+
454+
def projectRef = project
455+
doLast {
456+
String beatsVersion = projectRef.ext.get("artifactApiVersion")
457+
String downloadedFilebeatName = "filebeat-${beatsVersion}-${projectRef.ext.get("beatsArchitecture")}"
458+
projectRef.ext.set("unpackedFilebeatName", downloadedFilebeatName)
459+
460+
def res = SnapshotArtifactURLs.packageUrls("beats", beatsVersion, downloadedFilebeatName)
461+
projectRef.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: res.packageUrl)
462+
projectRef.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
463+
}
464+
}
465+
466+
tasks.register("downloadFilebeat", Download) {
467+
dependsOn prepareFilebeatDownload
468+
description = "Download Filebeat Snapshot for current branch version: ${version}"
453469

454470
project.ext.set("versionFound", true)
455471
inputs.file("${projectDir}/versions.yml")
456472

457-
doLast {
458-
download {
459-
String beatsVersion = project.ext.get("artifactApiVersion")
460-
String downloadedFilebeatName = "filebeat-${beatsVersion}-${project.ext.get("beatsArchitecture")}"
461-
project.ext.set("unpackedFilebeatName", downloadedFilebeatName)
473+
def projectRef = project
462474

463-
def res = SnapshotArtifactURLs.packageUrls("beats", beatsVersion, downloadedFilebeatName)
464-
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: res.packageUrl)
465-
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
475+
// Use lazy configuration to get values after prepareFilebeatDownload runs
476+
src { projectRef.ext.filebeatSnapshotUrl }
477+
dest { new File(projectRef.ext.filebeatDownloadLocation) }
466478

467-
src project.ext.filebeatSnapshotUrl
468-
onlyIfNewer true
479+
onlyIfNewer true
480+
retries 3
469481

470-
dest new File(project.ext.filebeatDownloadLocation)
471-
retries 3
472-
}
473-
System.out.println "Downloaded to ${project.ext.filebeatDownloadLocation}"
482+
doLast {
483+
System.out.println "Downloaded to ${projectRef.ext.filebeatDownloadLocation}"
474484
}
475485
}
476486

@@ -495,11 +505,12 @@ tasks.register("copyFilebeat") {
495505
tasks.register("checkEsSHA") {
496506
dependsOn configureArtifactInfo
497507

498-
description "Download ES version remote's fingerprint file"
508+
description = "Download ES version remote's fingerprint file"
499509

510+
def projectRef = project
500511
doLast {
501-
String esVersion = project.ext.get("artifactApiVersion")
502-
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
512+
String esVersion = projectRef.ext.get("artifactApiVersion")
513+
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${projectRef.ext.get("esArchitecture")}"
503514
String remoteSHA
504515

505516
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
@@ -529,30 +540,39 @@ tasks.register("checkEsSHA") {
529540
}
530541
}
531542

532-
tasks.register("downloadEs") {
533-
dependsOn = [configureArtifactInfo, checkEsSHA]
534-
535-
description "Download ES Snapshot for current branch version: ${version}"
536-
inputs.file("${projectDir}/versions.yml")
543+
tasks.register("prepareEsDownload") {
544+
dependsOn configureArtifactInfo
537545

546+
def projectRef = project
538547
doLast {
539-
download {
540-
String esVersion = project.ext.get("artifactApiVersion")
541-
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${project.ext.get("esArchitecture")}"
548+
String esVersion = projectRef.ext.get("artifactApiVersion")
549+
String downloadedElasticsearchName = "elasticsearch-${esVersion}-${projectRef.ext.get("esArchitecture")}"
542550

543-
project.ext.set("unpackedElasticsearchName", "elasticsearch-${esVersion}")
551+
projectRef.ext.set("unpackedElasticsearchName", "elasticsearch-${esVersion}")
544552

545-
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
546-
project.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: res.packageUrl)
547-
project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
553+
def res = SnapshotArtifactURLs.packageUrls("elasticsearch", esVersion, downloadedElasticsearchName)
554+
projectRef.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: res.packageUrl)
555+
projectRef.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
556+
}
557+
}
548558

549-
src project.ext.elasticsearchSnapshotURL
550-
onlyIfNewer true
551-
retries 3
552-
dest new File(project.ext.elasticsearchDownloadLocation)
553-
}
559+
tasks.register("downloadEs", Download) {
560+
dependsOn = [prepareEsDownload, checkEsSHA]
561+
562+
description = "Download ES Snapshot for current branch version: ${version}"
563+
inputs.file("${projectDir}/versions.yml")
554564

555-
System.out.println "Downloaded to ${project.ext.elasticsearchDownloadLocation}"
565+
def projectRef = project
566+
567+
src { projectRef.ext.elasticsearchSnapshotURL }
568+
dest { new File(projectRef.ext.elasticsearchDownloadLocation) }
569+
570+
onlyIfNewer true
571+
overwrite false
572+
retries 3
573+
574+
doLast {
575+
System.out.println "Downloaded to ${projectRef.ext.elasticsearchDownloadLocation}"
556576
}
557577
}
558578

@@ -609,7 +629,7 @@ tasks.register("generateLicenseReport", JavaExec) {
609629
String noticePath = "NOTICE.txt"
610630

611631
classpath = project.files([jarFile])
612-
main = "org.logstash.dependencies.Main"
632+
mainClass = "org.logstash.dependencies.Main"
613633
args licenseReportInputCSV,
614634
project.getBuildDir().toString() + "/licenseReportFolders.txt",
615635
licenseReportOutputCSV, noticePath
@@ -828,7 +848,7 @@ tasks.register("downloadJdk", Download) {
828848

829849
def jdkDetails = new JDKDetails(gradle.ext.versions.bundled_jdk, osName, jdkArch)
830850

831-
description "Download JDK ${jdkDetails.major}, OS: ${osName}"
851+
description = "Download JDK ${jdkDetails.major}, OS: ${osName}"
832852

833853
// find url of build artifact
834854
String artifactApiUrl = jdkDetails.createDownloadUrl()

gradle/wrapper/gradle-wrapper.jar

311 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
8890

8991
# Use the maximum available, or set MAX_FD != -1 to use that value.
9092
MAX_FD=maximum
@@ -112,7 +114,7 @@ case "$( uname )" in #(
112114
NONSTOP* ) nonstop=true ;;
113115
esac
114116

115-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
117+
CLASSPATH="\\\"\\\""
116118

117119

118120
# Determine the Java command to use to start the JVM.
@@ -203,15 +205,15 @@ fi
203205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204206

205207
# Collect all arguments for the java command:
206-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207209
# and any embedded shellness will be escaped.
208210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209211
# treated as '${Hostname}' itself on the command line.
210212

211213
set -- \
212214
"-Dorg.gradle.appname=$APP_BASE_NAME" \
213215
-classpath "$CLASSPATH" \
214-
org.gradle.wrapper.GradleWrapperMain \
216+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
215217
"$@"
216218

217219
# Stop when "xargs" is not available.

gradlew.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
@@ -68,11 +70,11 @@ goto fail
6870
:execute
6971
@rem Setup the command line
7072

71-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73+
set CLASSPATH=
7274

7375

7476
@rem Execute Gradle
75-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
77+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7678

7779
:end
7880
@rem End local scope for the variables with windows NT shell

logstash-core/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ configurations.archives {
103103

104104
tasks.register("javaTests", Test) {
105105
dependsOn ':bootstrap'
106+
testClassesDirs = sourceSets.test.output.classesDirs
107+
classpath = sourceSets.test.runtimeClasspath
106108
exclude '/org/logstash/RSpecTests.class'
107109
exclude '/org/logstash/config/ir/ConfigCompilerTest.class'
108110
exclude '/org/logstash/config/ir/CompiledPipelineTest.class'
@@ -136,6 +138,8 @@ javaTests.finalizedBy(jacocoTestReport)
136138

137139
tasks.register("rubyTests", Test) {
138140
dependsOn compileTestJava
141+
testClassesDirs = sourceSets.test.output.classesDirs
142+
classpath = sourceSets.test.runtimeClasspath
139143
inputs.files fileTree("${projectDir}/lib")
140144
inputs.files fileTree("${projectDir}/spec")
141145
systemProperty 'logstash.root.dir', projectDir.parent
@@ -171,10 +175,10 @@ tasks {
171175
artifacts {
172176
sources(sourcesJar) {
173177
// Weird Gradle quirk where type will be used for the extension, but only for sources
174-
type 'jar'
178+
type = 'jar'
175179
}
176180
javadoc(javadocJar) {
177-
type 'javadoc'
181+
type = 'javadoc'
178182
}
179183
}
180184

0 commit comments

Comments
 (0)