Skip to content

Commit

Permalink
chore(build): make Gradle less noisy (#5700)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yuri1969 authored and MilosPaunovic committed Nov 4, 2024
1 parent ef0d945 commit 7ebb918
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
70 changes: 46 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import net.e175.klaus.zip.ZipPrefixer
import org.owasp.dependencycheck.gradle.extension.AnalyzerExtension

buildscript {
repositories {
Expand All @@ -15,7 +16,7 @@ plugins {
id "java"
id 'java-library'
id "idea"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "com.gradleup.shadow" version "8.3.3"
id "application"

// test
Expand Down Expand Up @@ -51,9 +52,17 @@ idea {
/**********************************************************************************************************************\
* Main
**********************************************************************************************************************/
mainClassName = "io.kestra.cli.App"
sourceCompatibility = 21
targetCompatibility = 21
final mainClassName = "io.kestra.cli.App"
final targetJavaVersion = JavaVersion.VERSION_21

application {
mainClass = mainClassName
}

java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
}

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

sourceCompatibility = 21
targetCompatibility = 21
java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
}

repositories {
mavenCentral()
Expand Down Expand Up @@ -153,8 +164,10 @@ subprojects {
if (it.name != 'platform') {
apply plugin: "com.adarshr.test-logger"

sourceCompatibility = 21
targetCompatibility = 21
java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
}

dependencies {
// Platform
Expand Down Expand Up @@ -325,9 +338,12 @@ dependencyCheck {
failBuildOnCVSS = 7

// disable the .NET assembly analyzer as otherwise it wants to analyze EXE file
analyzers {
assemblyEnabled = false
}
analyzers(new Action<AnalyzerExtension>() {
@Override
void execute(AnalyzerExtension analyzerExtension) {
analyzerExtension.assemblyEnabled = false
}
})

// configure a suppression file
suppressionFile = "$projectDir/owasp-dependency-suppressions.xml"
Expand All @@ -340,7 +356,7 @@ dependencyCheck {
**********************************************************************************************************************/
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
options.compilerArgs.add("-Xlint:all")
Expand All @@ -349,7 +365,7 @@ allprojects {
}
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
}
Expand Down Expand Up @@ -394,20 +410,25 @@ shadowJar.dependsOn 'ui:assembleFrontend'
/**********************************************************************************************************************\
* Executable Jar
**********************************************************************************************************************/
def executableDir = file("${buildDir}/executable")
def executable = file("${buildDir}/executable/${project.name}-${project.version}")
def executableDir = layout.buildDirectory.dir("executable")
def executable = layout.buildDirectory.file("executable/${project.name}-${project.version}").get().asFile

task writeExecutableJar() {
tasks.register('writeExecutableJar') {
group "build"
description "Write an executable jar from shadow jar"
dependsOn = [shadowJar]

final shadowJarFile = tasks.shadowJar.outputs.files.singleFile
inputs.file shadowJarFile
outputs.file executable
outputs.cacheIf { true }

doFirst {
executableDir.mkdirs()
executableDir.get().asFile.mkdirs()
}

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

task executableJar(type: Zip) {
tasks.register('executableJar', Zip) {
group "build"
description "Zip the executable jar"
dependsOn = [writeExecutableJar]

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

from executableDir
archiveClassifier.set(null)
Expand All @@ -434,8 +455,9 @@ task executableJar(type: Zip) {
/**********************************************************************************************************************\
* Standalone
**********************************************************************************************************************/
task runLocal(type: JavaExec) {
tasks.register('runLocal', JavaExec) {
group = "application"
description = "Run Kestra as server local"
classpath = project(":cli").sourceSets.main.runtimeClasspath
mainClass = mainClassName
environment 'MICRONAUT_ENVIRONMENTS', 'override'
Expand Down Expand Up @@ -470,7 +492,7 @@ subprojects {
}
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
dependsOn = [':core:copyGradleProperties']
dependsOn = [':ui:assembleFrontend']
archiveClassifier.set('sources')
Expand All @@ -479,12 +501,12 @@ subprojects {
sourcesJar.dependsOn ':core:copyGradleProperties'
sourcesJar.dependsOn ':ui:assembleFrontend'

task javadocJar(type: Jar) {
tasks.register('javadocJar', Jar) {
archiveClassifier.set('javadoc')
from javadoc
}

task testsJar(type: Jar) {
tasks.register('testsJar', Jar) {
archiveClassifier.set('tests')
from sourceSets.test.output
}
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ configurations {
implementation.extendsFrom(micronaut)
}

task copyGradleProperties(type: Copy) {
tasks.register('copyGradleProperties', Copy) {
group = "build"
shouldRunAfter compileJava

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
/**********************************************************************************************************************\
* ./gradlew playwright
**********************************************************************************************************************/
task playwright(type: JavaExec) {
tasks.register('playwright', JavaExec) {
classpath sourceSets.test.runtimeClasspath
mainClass = 'com.microsoft.playwright.CLI'
}
Expand Down

0 comments on commit 7ebb918

Please sign in to comment.