Skip to content

Commit

Permalink
Use task avoidance API in gradle scripts (elastic#11914)
Browse files Browse the repository at this point in the history
* Use task avoidance API in gradle scripts

This commit uses the task avoidance api (tasks.register vs task.create/
task DSL), as recommended since Gradle 5.1

This should reduce the execution of unnecessary tasks in build jobs, and
hopefully improve build resiliency and execution time.
  • Loading branch information
robbavey authored May 29, 2020
1 parent 678a78c commit ac95667
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 42 deletions.
68 changes: 42 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,45 @@ def assemblyDeps = [downloadAndInstallJRuby, assemble] + subprojects.collect {
it.tasks.findByName("assemble")
}

task installBundler(dependsOn: assemblyDeps) {
outputs.files file("${projectDir}/vendor/bundle/jruby/2.5.0/bin/bundle")
doLast {
tasks.register("installBundler") {
dependsOn assemblyDeps
outputs.files file("${projectDir}/vendor/bundle/jruby/2.5.0/bin/bundle")
doLast {
gem(projectDir, buildDir, "bundler", "1.17.3", "${projectDir}/vendor/bundle/jruby/2.5.0")
}
}

task bootstrap(dependsOn: installBundler) {
doLast {
tasks.register("bootstrap"){
dependsOn installBundler
doLast {
setupJruby(projectDir, buildDir)
}
}


task installDefaultGems(dependsOn: bootstrap) {
tasks.register("installDefaultGems") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'plugin:install-default')
}
}

task installTestGems(dependsOn: bootstrap) {
doLast {
tasks.register("installTestGems") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'plugin:install-development-dependencies')
}
}

task compileGrammar(dependsOn: bootstrap) {
tasks.register("compileGrammar") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'compile:grammar')
}
}

task assembleTarDistribution(dependsOn: bootstrap) {
tasks.register("assembleTarDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
Expand All @@ -196,7 +202,8 @@ task assembleTarDistribution(dependsOn: bootstrap) {
}
}

task assembleOssTarDistribution(dependsOn: bootstrap) {
tasks.register("assembleOssTarDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
Expand All @@ -210,7 +217,8 @@ task assembleOssTarDistribution(dependsOn: bootstrap) {
}
}

task assembleZipDistribution(dependsOn: bootstrap) {
tasks.register("assembleZipDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
Expand All @@ -226,7 +234,8 @@ task assembleZipDistribution(dependsOn: bootstrap) {
}
}

task assembleOssZipDistribution(dependsOn: bootstrap) {
tasks.register("assembleOssZipDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
Expand All @@ -252,7 +261,8 @@ project(":logstash-core") {

def logstashBuildDir = "${buildDir}/logstash-${project.version}-SNAPSHOT"

task unpackTarDistribution(dependsOn: assembleTarDistribution, type: Copy) {
tasks.register("unpackTarDistribution", Copy) {
dependsOn assembleTarDistribution
def tar = file("${buildDir}/logstash-${project.version}-SNAPSHOT.tar.gz")
inputs.files tar
outputs.files fileTree(logstashBuildDir)
Expand All @@ -264,14 +274,16 @@ def qaVendorPath = "${buildDir}/qa/integration/vendor"
def qaBundledGemPath = "${qaVendorPath}/jruby/2.5.0"
def qaBundleBin = "${qaBundledGemPath}/bin/bundle"

task installIntegrationTestBundler(dependsOn: unpackTarDistribution) {
outputs.files fileTree("${qaBundledGemPath}/gems/bundler-1.17.3")
tasks.register("installIntegrationTestBundler"){
dependsOn unpackTarDistribution
outputs.files fileTree("${qaBundledGemPath}/gems/bundler-1.17.3")
doLast {
gem(projectDir, buildDir, "bundler", "1.17.3", qaBundledGemPath)
}
}

task installIntegrationTestGems(dependsOn: installIntegrationTestBundler) {
tasks.register("installIntegrationTestGems") {
dependsOn installIntegrationTestBundler
inputs.files file("${projectDir}/qa/integration/Gemfile")
inputs.files file("${projectDir}/qa/integration/integration_tests.gemspec")
inputs.files file("${logstashBuildDir}/Gemfile")
Expand Down Expand Up @@ -300,11 +312,13 @@ project(":logstash-integration-tests") {
}
}

task runIntegrationTests(dependsOn: [tasks.getByPath(":logstash-integration-tests:integrationTests")]) {}
tasks.register("runIntegrationTests"){
dependsOn tasks.getByPath(":logstash-integration-tests:integrationTests")
}

task generateLicenseReport(type: JavaExec) {
dependsOn("generateLicenseReportInputs")
dependsOn(":dependencies-report:assemble")
tasks.register("generateLicenseReport", JavaExec) {
dependsOn generateLicenseReportInputs
dependsOn ":dependencies-report:assemble"

def jarFile = project('dependencies-report').getBuildDir().toString() + "/libs/dependencies-report.jar"

Expand All @@ -319,7 +333,7 @@ task generateLicenseReport(type: JavaExec) {
licenseReportOutputCSV, noticePath
}

task generateLicenseReportInputs() {
tasks.register("generateLicenseReportInputs") {
dependsOn subprojects.generateLicenseReport

// write location of all license reports for subprojects containing artifacts that are distributed to single file
Expand All @@ -342,7 +356,8 @@ task generateLicenseReportInputs() {
}
}

task generatePluginsVersion(dependsOn: installDefaultGems) {
tasks.register("generatePluginsVersion") {
dependsOn installDefaultGems
doLast {
rake(projectDir, buildDir, 'generate_plugins_version')
}
Expand All @@ -355,7 +370,7 @@ check.dependsOn runIntegrationTests

String artifactsVersionApi = "https://artifacts-api.elastic.co/v1/versions/"

task downloadEs(type: Download) {
tasks.register("downloadEs", Download) {
description "Download ES Snapshot for current branch version: ${version}"

doFirst {
Expand Down Expand Up @@ -425,11 +440,12 @@ task downloadEs(type: Download) {
}
}

task deleteLocalEs(type: Delete) {
tasks.register("deleteLocalEs", Delete) {
delete ('./build/elasticsearch')
}

task copyEs(type: Copy, dependsOn: [downloadEs, deleteLocalEs]) {
tasks.register("copyEs", Copy){
dependsOn = [downloadEs, deleteLocalEs]
from tarTree(resources.gzip(project.ext.elasticsearchDownloadLocation))
into "./build/"
doLast {
Expand Down
4 changes: 3 additions & 1 deletion logstash-core/benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ shadowJar {
archiveVersion = ''
}

task jmh(type: JavaExec, dependsOn: [':logstash-core-benchmarks:clean', ':logstash-core-benchmarks:shadowJar']) {
tasks.register("jmh", JavaExec) {

dependsOn=[':logstash-core-benchmarks:clean', ':logstash-core-benchmarks:shadowJar']

main = "-jar"

Expand Down
17 changes: 10 additions & 7 deletions logstash-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,34 @@ buildscript {
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
tasks.register("sourcesJar", Jar) {
dependsOn classes
from sourceSets.main.allSource
archiveClassifier = 'sources'
archiveExtension = 'jar'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register("javadocJar", Jar) {
dependsOn javadoc
from javadoc.destinationDir
archiveClassifier = 'javadoc'
archiveExtension = 'jar'
}

task copyRuntimeLibs(type: Copy) {
tasks.register("copyRuntimeLibs", Copy) {
into project.file('lib/jars/')
from configurations.compileClasspath, configurations.runtimeClasspath
}

// copy jar file into the gem lib dir but without the version number in filename
task copyGemjar(type: Copy, dependsOn: [sourcesJar, copyRuntimeLibs]) {
tasks.register("copyGemjar", Copy) {
dependsOn=[sourcesJar, copyRuntimeLibs]
from project.jar
into project.file('lib/jars/')
rename(/(.+)-${project.version}.jar/, '$1.jar')
}

task cleanGemjar {
tasks.register("cleanGemjar") {
delete fileTree(project.file('lib/jars/')) {
include '*.jar'
}
Expand All @@ -84,7 +87,7 @@ configurations.archives {
extendsFrom configurations.javadoc
}

task javaTests(type: Test) {
tasks.register("javaTests", Test) {
exclude '/org/logstash/RSpecTests.class'
exclude '/org/logstash/config/ir/ConfigCompilerTest.class'
exclude '/org/logstash/config/ir/CompiledPipelineTest.class'
Expand All @@ -97,7 +100,7 @@ task javaTests(type: Test) {
exclude '/org/logstash/plugins/factory/PluginFactoryExtTest.class'
}

task rubyTests(type: Test) {
tasks.register("rubyTests", Test) {
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/spec")
systemProperty 'logstash.core.root.dir', projectDir.absolutePath
Expand Down
2 changes: 1 addition & 1 deletion qa/integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test {
exclude '/**'
}

task integrationTests(type: Test) {
tasks.register("integrationTests", Test) {
inputs.files fileTree("${projectDir}/services")
inputs.files fileTree("${projectDir}/framework")
inputs.files fileTree("${projectDir}/fixtures")
Expand Down
13 changes: 8 additions & 5 deletions rubyUtils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def customJRubyDir = project.hasProperty("custom.jruby.path") ? project.property
def customJRubyVersion = customJRubyDir == "" ? "" : Files.readAllLines(Paths.get(customJRubyDir, "VERSION")).get(0).trim()
def customJRubyTar = customJRubyDir == "" ? "" : (customJRubyDir + "/maven/jruby-dist/target/jruby-dist-${customJRubyVersion}-bin.tar.gz")

task downloadJRuby(type: Download) {
tasks.register("downloadJRuby", Download) {
description "Download JRuby artifact from this specific URL: ${jRubyURL}"
src jRubyURL
onlyIfNewer true
Expand All @@ -219,7 +219,8 @@ task downloadJRuby(type: Download) {

downloadJRuby.onlyIf { customJRubyDir == "" }

task verifyFile(dependsOn: downloadJRuby, type: Verify) {
tasks.register("verifyFile", Verify) {
dependsOn downloadJRuby
description "Verify the SHA1 of the download JRuby artifact"
inputs.file(jrubyTarPath)
outputs.file(jrubyTarPath)
Expand All @@ -231,7 +232,7 @@ task verifyFile(dependsOn: downloadJRuby, type: Verify) {
verifyFile.onlyIf { customJRubyDir == "" }
verifyFile.onlyIf { doChecksum }

task buildCustomJRuby(type: Exec) {
tasks.register("buildCustomJRuby", Exec) {
description "Build tar.gz and .jar artifacts from JRuby source directory"
workingDir (customJRubyDir == "" ? "./" : customJRubyDir)
commandLine './mvnw', 'clean', 'install', '-Pdist', '-Pcomplete'
Expand All @@ -244,7 +245,8 @@ task buildCustomJRuby(type: Exec) {

buildCustomJRuby.onlyIf { customJRubyDir != "" }

task installCustomJRuby(dependsOn: buildCustomJRuby, type: Copy) {
tasks.register("installCustomJRuby", Copy) {
dependsOn buildCustomJRuby
description "Install custom built JRuby in the vendor directory"
inputs.file(customJRubyTar)
outputs.dir("${projectDir}/vendor/jruby")
Expand All @@ -260,7 +262,8 @@ task installCustomJRuby(dependsOn: buildCustomJRuby, type: Copy) {
installCustomJRuby.onlyIf { customJRubyDir != "" }


task downloadAndInstallJRuby(dependsOn: [verifyFile, installCustomJRuby], type: Copy) {
tasks.register("downloadAndInstallJRuby", Copy) {
dependsOn=[verifyFile, installCustomJRuby]
description "Install JRuby in the vendor directory"
inputs.file(jrubyTarPath)
outputs.dir("${projectDir}/vendor/jruby")
Expand Down
4 changes: 2 additions & 2 deletions x-pack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ test {
exclude '/**'
}

task rubyTests(type: Test) {
tasks.register("rubyTests", Test) {
inputs.files fileTree("${projectDir}/spec")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
systemProperty 'logstash.core.root.dir', projectDir.absolutePath
include '/org/logstash/xpack/test/RSpecTests.class'
}

task rubyIntegrationTests(type: Test) {
tasks.register("rubyIntegrationTests", Test) {
inputs.files fileTree("${projectDir}/qa")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
Expand Down

0 comments on commit ac95667

Please sign in to comment.