Skip to content

Commit 652cb7d

Browse files
authored
Make build Gradle 2.14 / 3.x compatible (elastic#22669)
This changes build files so that building Elasticsearch works with both Gradle 2.13 as well as higher versions of Gradle (tested 2.14 and 3.3), enabling a smooth transition from Gradle 2.13 to 3.x.
1 parent ce765f7 commit 652cb7d

File tree

10 files changed

+81
-19
lines changed

10 files changed

+81
-19
lines changed

buildSrc/build.gradle

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@ apply plugin: 'groovy'
2323

2424
group = 'org.elasticsearch.gradle'
2525

26-
// TODO: remove this when upgrading to a version that supports ProgressLogger
27-
// gradle 2.14 made internal apis unavailable to plugins, and gradle considered
28-
// ProgressLogger to be an internal api. Until this is made available again,
29-
// we can't upgrade without losing our nice progress logging
30-
// NOTE that this check duplicates that in BuildPlugin, but we need to check
31-
// early here before trying to compile the broken classes in buildSrc
32-
if (GradleVersion.current() != GradleVersion.version('2.13')) {
33-
throw new GradleException('Gradle 2.13 is required to build elasticsearch')
26+
if (GradleVersion.current() < GradleVersion.version('2.13')) {
27+
throw new GradleException('Gradle 2.13+ is required to build elasticsearch')
3428
}
3529

3630
if (project == rootProject) {
@@ -96,9 +90,25 @@ dependencies {
9690
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
9791
compile 'de.thetaphi:forbiddenapis:2.2'
9892
compile 'org.apache.rat:apache-rat:0.11'
99-
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.0.1'
10093
}
10194

95+
// Gradle version-specific options (allows build to run with Gradle 2.13 as well as 2.14+/3.+)
96+
if (GradleVersion.current() == GradleVersion.version("2.13")) {
97+
// ProgressLogger(-Factory) classes are part of the public Gradle API
98+
// Add default imports for (org.gradle.logging)
99+
compileGroovy.groovyOptions.configurationScript = file('src/compile/groovy/gradle-2.13-loggers.groovy')
100+
dependencies {
101+
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.0.1' // last version compatible with Gradle 2.13
102+
}
103+
} else {
104+
// Gradle 2.14+ removed ProgressLogger(-Factory) classes from the public APIs
105+
// Use logging dependency and add default imports for "org.gradle.internal.logging.progress"
106+
compileGroovy.groovyOptions.configurationScript = file('src/compile/groovy/gradle-2.14-loggers.groovy')
107+
dependencies {
108+
compileOnly "org.gradle:gradle-logging:${GradleVersion.current().getVersion()}"
109+
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0' // Gradle 2.14 requires a version > 1.0.1
110+
}
111+
}
102112

103113
/*****************************************************************************
104114
* Bootstrap repositories *
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.codehaus.groovy.control.customizers.ImportCustomizer
21+
22+
def imports = new ImportCustomizer()
23+
imports.addImports(
24+
'org.gradle.logging.ProgressLogger',
25+
'org.gradle.logging.ProgressLoggerFactory')
26+
configuration.addCompilationCustomizers(imports)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.codehaus.groovy.control.customizers.ImportCustomizer
21+
22+
def imports = new ImportCustomizer()
23+
imports.addImports(
24+
'org.gradle.internal.logging.progress.ProgressLogger',
25+
'org.gradle.internal.logging.progress.ProgressLoggerFactory')
26+
configuration.addCompilationCustomizers(imports)

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingTask.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import org.gradle.api.tasks.Optional
1919
import org.gradle.api.tasks.TaskAction
2020
import org.gradle.api.tasks.util.PatternFilterable
2121
import org.gradle.api.tasks.util.PatternSet
22-
import org.gradle.logging.ProgressLoggerFactory
2322
import org.gradle.util.ConfigureUtil
2423

2524
import javax.inject.Inject

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/TestProgressLogger.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedStartEvent
2525
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteResultEvent
2626
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent
2727
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
28-
import org.gradle.logging.ProgressLogger
29-
import org.gradle.logging.ProgressLoggerFactory
3028

3129
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
3230
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.ERROR

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ class BuildPlugin implements Plugin<Project> {
418418
// hack until gradle supports java 9's new "--release" arg
419419
assert minimumJava == JavaVersion.VERSION_1_8
420420
options.compilerArgs << '--release' << '8'
421-
project.sourceCompatibility = null
422-
project.targetCompatibility = null
421+
doFirst{
422+
sourceCompatibility = null
423+
targetCompatibility = null
424+
}
423425
}
424426
}
425427
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import com.carrotsearch.gradle.junit4.LoggingOutputStream
2222
import groovy.transform.PackageScope
2323
import org.gradle.api.GradleScriptException
2424
import org.gradle.api.logging.Logger
25-
import org.gradle.logging.ProgressLogger
26-
import org.gradle.logging.ProgressLoggerFactory
2725

2826
import java.util.regex.Matcher
2927

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantCommandTask.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package org.elasticsearch.gradle.vagrant
2121
import org.apache.commons.io.output.TeeOutputStream
2222
import org.elasticsearch.gradle.LoggedExec
2323
import org.gradle.api.tasks.Input
24-
import org.gradle.logging.ProgressLoggerFactory
2524

2625
import javax.inject.Inject
2726

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ package org.elasticsearch.gradle.vagrant
2020

2121
import com.carrotsearch.gradle.junit4.LoggingOutputStream
2222
import org.gradle.api.logging.Logger
23-
import org.gradle.logging.ProgressLogger
24-
import org.gradle.logging.ProgressLoggerFactory
2523

2624
/**
2725
* Adapts an OutputStream being written to by vagrant into a ProcessLogger. It

plugins/repository-hdfs/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,9 @@ thirdPartyAudit.excludes = [
368368
'org.apache.log4j.helpers.ISO8601DateFormat',
369369
'org.apache.log4j.spi.ThrowableInformation'
370370
]
371+
372+
// Gradle 2.13 bundles org.slf4j.impl.StaticLoggerBinder in its core.jar which leaks into the forbidden APIs ant task
373+
// Gradle 2.14+ does not bundle this class anymore so we need to properly exclude it here.
374+
if (GradleVersion.current() > GradleVersion.version("2.13")) {
375+
thirdPartyAudit.excludes += ['org.slf4j.impl.StaticLoggerBinder']
376+
}

0 commit comments

Comments
 (0)