logstash/logstash-core/build.gradle
Rob Bavey b2da4449a5
Use task avoidance API in gradle scripts (#11914) (#11943)
* 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.
2020-05-29 11:52:01 -04:00

186 lines
6.6 KiB
Groovy

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.nio.file.Files
import java.nio.file.Paths
import org.yaml.snakeyaml.Yaml
// fetch version from Logstash's master versions.yml file
def versionMap = (Map) (new Yaml()).load(new File("$projectDir/../versions.yml").text)
description = """Logstash Core Java"""
version = versionMap['logstash-core']
String jrubyVersion = versionMap['jruby']['version']
String jacksonVersion = versionMap['jackson']
String jacksonDatabindVersion = versionMap['jackson-databind']
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.yaml:snakeyaml:1.17'
}
}
tasks.register("sourcesJar", Jar) {
dependsOn classes
from sourceSets.main.allSource
archiveClassifier = 'sources'
archiveExtension = 'jar'
}
tasks.register("javadocJar", Jar) {
dependsOn javadoc
from javadoc.destinationDir
archiveClassifier = 'javadoc'
archiveExtension = 'jar'
}
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
tasks.register("copyGemjar", Copy) {
dependsOn=[sourcesJar, copyRuntimeLibs]
from project.jar
into project.file('lib/jars/')
rename(/(.+)-${project.version}.jar/, '$1.jar')
}
tasks.register("cleanGemjar") {
delete fileTree(project.file('lib/jars/')) {
include '*.jar'
}
}
clean.dependsOn(cleanGemjar)
jar.finalizedBy(copyGemjar)
assemble.dependsOn(copyGemjar)
configurations.create('sources')
configurations.create('javadoc')
configurations.archives {
extendsFrom configurations.sources
extendsFrom configurations.javadoc
}
tasks.register("javaTests", Test) {
exclude '/org/logstash/RSpecTests.class'
exclude '/org/logstash/config/ir/ConfigCompilerTest.class'
exclude '/org/logstash/config/ir/CompiledPipelineTest.class'
exclude '/org/logstash/config/ir/EventConditionTest.class'
exclude '/org/logstash/config/ir/compiler/OutputDelegatorTest.class'
exclude '/org/logstash/config/ir/compiler/JavaCodecDelegatorTest.class'
exclude '/org/logstash/plugins/NamespacedMetricImplTest.class'
exclude '/org/logstash/plugins/CounterMetricImplTest.class'
exclude '/org/logstash/plugins/PluginFactoryExtTest.class'
}
tasks.register("rubyTests", Test) {
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/spec")
systemProperty 'logstash.core.root.dir', projectDir.absolutePath
include '/org/logstash/RSpecTests.class'
include '/org/logstash/config/ir/ConfigCompilerTest.class'
include '/org/logstash/config/ir/CompiledPipelineTest.class'
include '/org/logstash/config/ir/EventConditionTest.class'
include '/org/logstash/config/ir/compiler/OutputDelegatorTest.class'
include '/org/logstash/config/ir/compiler/JavaCodecDelegatorTest.class'
include '/org/logstash/plugins/NamespacedMetricImplTest.class'
include '/org/logstash/plugins/CounterMetricImplTest.class'
include '/org/logstash/plugins/PluginFactoryExtTest.class'
}
test {
exclude '/**'
}
test.dependsOn javaTests, rubyTests
artifacts {
sources(sourcesJar) {
// Weird Gradle quirk where type will be used for the extension, but only for sources
type 'jar'
}
javadoc(javadocJar) {
type 'javadoc'
}
}
configurations {
provided
}
project.sourceSets {
main.compileClasspath += project.configurations.provided
main.runtimeClasspath += project.configurations.provided
test.compileClasspath += project.configurations.provided
test.runtimeClasspath += project.configurations.provided
}
project.javadoc.classpath += project.configurations.provided
idea {
module {
scopes.PROVIDED.plus += [project.configurations.provided]
}
}
def customJRubyDir = project.hasProperty("custom.jruby.path") ? project.property("custom.jruby.path") : ""
def customJRubyVersion = customJRubyDir == "" ? "" : Files.readAllLines(Paths.get(customJRubyDir, "VERSION")).get(0).trim()
dependencies {
implementation 'org.apache.logging.log4j:log4j-api:2.12.1'
annotationProcessor 'org.apache.logging.log4j:log4j-core:2.12.1'
api 'org.apache.logging.log4j:log4j-core:2.12.1'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.12.1'
implementation('org.reflections:reflections:0.9.11') {
exclude group: 'com.google.guava', module: 'guava'
}
implementation 'commons-codec:commons-codec:1.13'
// Jackson version moved to versions.yml in the project root (the JrJackson version is there too)
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
api "com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}"
api "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
implementation 'org.codehaus.janino:janino:3.1.0'
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${jacksonVersion}"
if (customJRubyDir == "") {
api "org.jruby:jruby-complete:${jrubyVersion}"
} else {
api files(customJRubyDir + "/maven/jruby-complete/target/jruby-complete-${customJRubyVersion}.jar")
}
implementation group: 'com.google.guava', name: 'guava', version: '24.1.1-jre'
// WARNING: DO NOT UPGRADE "google-java-format"
// later versions require GPL licensed code in javac-shaded that is
// Apache2 incompatible
implementation('com.google.googlejavaformat:google-java-format:1.1') {
exclude group: 'com.google.guava', module: 'guava'
}
implementation 'org.javassist:javassist:3.26.0-GA'
testImplementation 'org.apache.logging.log4j:log4j-core:2.12.1:tests'
testImplementation 'junit:junit:4.12'
testImplementation 'net.javacrumbs.json-unit:json-unit:2.3.0'
testImplementation 'org.elasticsearch:securemock:1.2'
testImplementation 'org.assertj:assertj-core:3.11.1'
}