Skip to content

Commit 7ebb918

Browse files
yuri1969MilosPaunovic
authored andcommitted
chore(build): make Gradle less noisy (#5700)
* Fix Idea-reported problems * Minimize Gradle 9.0-related warnings * Migrate Shadow plugin The plugin ID `com.github.johnrengelman.shadow` is no longer maintained. See: GradleUp/shadow#908 * Make Shadow JAR-related task incremental
1 parent ef0d945 commit 7ebb918

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

build.gradle

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import net.e175.klaus.zip.ZipPrefixer
2+
import org.owasp.dependencycheck.gradle.extension.AnalyzerExtension
23

34
buildscript {
45
repositories {
@@ -15,7 +16,7 @@ plugins {
1516
id "java"
1617
id 'java-library'
1718
id "idea"
18-
id "com.github.johnrengelman.shadow" version "8.1.1"
19+
id "com.gradleup.shadow" version "8.3.3"
1920
id "application"
2021

2122
// test
@@ -51,9 +52,17 @@ idea {
5152
/**********************************************************************************************************************\
5253
* Main
5354
**********************************************************************************************************************/
54-
mainClassName = "io.kestra.cli.App"
55-
sourceCompatibility = 21
56-
targetCompatibility = 21
55+
final mainClassName = "io.kestra.cli.App"
56+
final targetJavaVersion = JavaVersion.VERSION_21
57+
58+
application {
59+
mainClass = mainClassName
60+
}
61+
62+
java {
63+
sourceCompatibility = targetJavaVersion
64+
targetCompatibility = targetJavaVersion
65+
}
5766

5867
dependencies {
5968
implementation project(":cli")
@@ -67,8 +76,10 @@ allprojects {
6776
if (it.name != 'platform') {
6877
group "io.kestra"
6978

70-
sourceCompatibility = 21
71-
targetCompatibility = 21
79+
java {
80+
sourceCompatibility = targetJavaVersion
81+
targetCompatibility = targetJavaVersion
82+
}
7283

7384
repositories {
7485
mavenCentral()
@@ -153,8 +164,10 @@ subprojects {
153164
if (it.name != 'platform') {
154165
apply plugin: "com.adarshr.test-logger"
155166

156-
sourceCompatibility = 21
157-
targetCompatibility = 21
167+
java {
168+
sourceCompatibility = targetJavaVersion
169+
targetCompatibility = targetJavaVersion
170+
}
158171

159172
dependencies {
160173
// Platform
@@ -325,9 +338,12 @@ dependencyCheck {
325338
failBuildOnCVSS = 7
326339

327340
// disable the .NET assembly analyzer as otherwise it wants to analyze EXE file
328-
analyzers {
329-
assemblyEnabled = false
330-
}
341+
analyzers(new Action<AnalyzerExtension>() {
342+
@Override
343+
void execute(AnalyzerExtension analyzerExtension) {
344+
analyzerExtension.assemblyEnabled = false
345+
}
346+
})
331347

332348
// configure a suppression file
333349
suppressionFile = "$projectDir/owasp-dependency-suppressions.xml"
@@ -340,7 +356,7 @@ dependencyCheck {
340356
**********************************************************************************************************************/
341357
allprojects {
342358
gradle.projectsEvaluated {
343-
tasks.withType(JavaCompile) {
359+
tasks.withType(JavaCompile).configureEach {
344360
options.encoding = "UTF-8"
345361
options.compilerArgs.add("-parameters")
346362
options.compilerArgs.add("-Xlint:all")
@@ -349,7 +365,7 @@ allprojects {
349365
}
350366
}
351367

352-
tasks.withType(JavaCompile) {
368+
tasks.withType(JavaCompile).configureEach {
353369
options.encoding = "UTF-8"
354370
options.compilerArgs.add("-parameters")
355371
}
@@ -394,20 +410,25 @@ shadowJar.dependsOn 'ui:assembleFrontend'
394410
/**********************************************************************************************************************\
395411
* Executable Jar
396412
**********************************************************************************************************************/
397-
def executableDir = file("${buildDir}/executable")
398-
def executable = file("${buildDir}/executable/${project.name}-${project.version}")
413+
def executableDir = layout.buildDirectory.dir("executable")
414+
def executable = layout.buildDirectory.file("executable/${project.name}-${project.version}").get().asFile
399415

400-
task writeExecutableJar() {
416+
tasks.register('writeExecutableJar') {
401417
group "build"
402418
description "Write an executable jar from shadow jar"
403419
dependsOn = [shadowJar]
404420

421+
final shadowJarFile = tasks.shadowJar.outputs.files.singleFile
422+
inputs.file shadowJarFile
423+
outputs.file executable
424+
outputs.cacheIf { true }
425+
405426
doFirst {
406-
executableDir.mkdirs()
427+
executableDir.get().asFile.mkdirs()
407428
}
408429

409430
doLast {
410-
executable.setBytes(file("${buildDir}/libs/${project.name}-${project.version}.jar").readBytes())
431+
executable.setBytes(shadowJarFile.readBytes())
411432
ByteArrayOutputStream executableBytes = new ByteArrayOutputStream()
412433
executableBytes.write("\n: <<END_OF_KESTRA_SELFRUN\r\n".getBytes())
413434
executableBytes.write(file("gradle/jar/selfrun.bat").readBytes())
@@ -419,13 +440,13 @@ task writeExecutableJar() {
419440
}
420441
}
421442

422-
task executableJar(type: Zip) {
443+
tasks.register('executableJar', Zip) {
423444
group "build"
424445
description "Zip the executable jar"
425446
dependsOn = [writeExecutableJar]
426447

427448
archiveFileName = "${project.name}-${project.version}.zip"
428-
destinationDirectory = file("${buildDir}/archives")
449+
destinationDirectory = layout.buildDirectory.dir('archives')
429450

430451
from executableDir
431452
archiveClassifier.set(null)
@@ -434,8 +455,9 @@ task executableJar(type: Zip) {
434455
/**********************************************************************************************************************\
435456
* Standalone
436457
**********************************************************************************************************************/
437-
task runLocal(type: JavaExec) {
458+
tasks.register('runLocal', JavaExec) {
438459
group = "application"
460+
description = "Run Kestra as server local"
439461
classpath = project(":cli").sourceSets.main.runtimeClasspath
440462
mainClass = mainClassName
441463
environment 'MICRONAUT_ENVIRONMENTS', 'override'
@@ -470,7 +492,7 @@ subprojects {
470492
}
471493
}
472494

473-
task sourcesJar(type: Jar) {
495+
tasks.register('sourcesJar', Jar) {
474496
dependsOn = [':core:copyGradleProperties']
475497
dependsOn = [':ui:assembleFrontend']
476498
archiveClassifier.set('sources')
@@ -479,12 +501,12 @@ subprojects {
479501
sourcesJar.dependsOn ':core:copyGradleProperties'
480502
sourcesJar.dependsOn ':ui:assembleFrontend'
481503

482-
task javadocJar(type: Jar) {
504+
tasks.register('javadocJar', Jar) {
483505
archiveClassifier.set('javadoc')
484506
from javadoc
485507
}
486508

487-
task testsJar(type: Jar) {
509+
tasks.register('testsJar', Jar) {
488510
archiveClassifier.set('tests')
489511
from sourceSets.test.output
490512
}

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ configurations {
33
implementation.extendsFrom(micronaut)
44
}
55

6-
task copyGradleProperties(type: Copy) {
6+
tasks.register('copyGradleProperties', Copy) {
77
group = "build"
88
shouldRunAfter compileJava
99

e2e-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
/**********************************************************************************************************************\
1111
* ./gradlew playwright
1212
**********************************************************************************************************************/
13-
task playwright(type: JavaExec) {
13+
tasks.register('playwright', JavaExec) {
1414
classpath sourceSets.test.runtimeClasspath
1515
mainClass = 'com.microsoft.playwright.CLI'
1616
}

0 commit comments

Comments
 (0)