Build: Consolidate dependencies specified in multiple places

Some dependencies must be specified in a couple places in the build.
e.g. randomized runner is specified both in buildSrc (for the gradle
wrapper plugin), as well as in the test-framework.

This change creates buildSrc/versions.properties which acts similar to
the set of shared version properties we used to have in the maven parent
pom.
This commit is contained in:
Ryan Ernst 2015-11-09 23:34:22 -08:00
parent 08b6148bb8
commit 7a6155e12f
15 changed files with 107 additions and 95 deletions

View File

@ -31,6 +31,9 @@ buildscript {
// common maven publishing configuration // common maven publishing configuration
subprojects { subprojects {
group = 'org.elasticsearch'
version = org.elasticsearch.gradle.VersionProperties.elasticsearch
plugins.withType(NexusPlugin).whenPluginAdded { plugins.withType(NexusPlugin).whenPluginAdded {
modifyPom { modifyPom {
project { project {
@ -91,34 +94,12 @@ allprojects {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = sourceCompatibility targetCompatibility = sourceCompatibility
// dependency versions that are used in more than one place
versions = [
lucene: "${luceneVersion}",
randomizedrunner: '2.2.0',
httpclient: '4.3.6'
]
// for eclipse hacks... // for eclipse hacks...
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse') isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
} }
} }
subprojects { subprojects {
repositories {
mavenCentral()
maven {
name 'sonatype-snapshots'
url 'http://oss.sonatype.org/content/repositories/snapshots/'
}
if (versions.lucene.contains('-snapshot')) {
String revision = (luceneVersion =~ /\d\.\d\.\d-snapshot-(\d+)/)[0][1]
maven {
name 'lucene-snapshots'
url "http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/${revision}"
}
}
}
// include license and notice in jars // include license and notice in jars
gradle.projectsEvaluated { gradle.projectsEvaluated {
tasks.withType(Jar) { tasks.withType(Jar) {

View File

@ -1,4 +1,21 @@
import org.apache.tools.ant.filters.ReplaceTokens /*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.
*/
plugins { plugins {
id 'groovy' id 'groovy'
@ -8,16 +25,13 @@ plugins {
apply plugin: 'idea' apply plugin: 'idea'
apply plugin: 'eclipse' apply plugin: 'eclipse'
/*idea {
project {
languageLevel = '1.8'
vcs = 'Git'
}
}*/
group = 'org.elasticsearch.gradle' group = 'org.elasticsearch.gradle'
archivesBaseName = 'build-tools' archivesBaseName = 'build-tools'
Properties props = new Properties()
props.load(project.file('version.properties').newDataInputStream())
version = props.getProperty('elasticsearch')
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
@ -30,8 +44,8 @@ repositories {
dependencies { dependencies {
compile gradleApi() compile gradleApi()
compile localGroovy() compile localGroovy()
compile 'com.carrotsearch.randomizedtesting:junit4-ant:2.2.0' compile "com.carrotsearch.randomizedtesting:junit4-ant:${props.getProperty('randomizedrunner')}"
compile('junit:junit:4.11') { compile("junit:junit:${props.getProperty('junit')}") {
transitive = false transitive = false
} }
compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3' compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
@ -41,25 +55,12 @@ dependencies {
compile 'de.thetaphi:forbiddenapis:2.0' compile 'de.thetaphi:forbiddenapis:2.0'
} }
Properties props = new Properties()
props.load(project.file('../gradle.properties').newDataInputStream())
version = props.getProperty('version')
processResources { processResources {
inputs.file('../gradle.properties') inputs.file('version.properties')
filter ReplaceTokens, tokens: [ from 'version.properties'
'version': props.getProperty('version'),
'luceneVersion': props.getProperty('luceneVersion')
]
} }
extraArchive { extraArchive {
javadoc = false javadoc = false
tests = false tests = false
} }
eclipse {
classpath {
defaultOutputDir = new File(file('build'), 'eclipse')
}
}

View File

@ -24,6 +24,7 @@ import org.gradle.api.JavaVersion
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.util.VersionNumber import org.gradle.util.VersionNumber
@ -36,6 +37,7 @@ class BuildPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
globalBuildInfo(project) globalBuildInfo(project)
configureRepositories(project)
project.pluginManager.apply('java') project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing') project.pluginManager.apply('carrotsearch.randomized-testing')
// these plugins add lots of info to our jars // these plugins add lots of info to our jars
@ -45,6 +47,7 @@ class BuildPlugin implements Plugin<Project> {
project.pluginManager.apply('nebula.info-scm') project.pluginManager.apply('nebula.info-scm')
project.pluginManager.apply('nebula.info-jar') project.pluginManager.apply('nebula.info-jar')
project.ext.versions = VersionProperties.versions
configureCompile(project) configureCompile(project)
configureJarManifest(project) configureJarManifest(project)
configureTest(project) configureTest(project)
@ -75,6 +78,24 @@ class BuildPlugin implements Plugin<Project> {
} }
} }
static void configureRepositories(Project project) {
RepositoryHandler repos = project.repositories
repos.mavenCentral()
repos.maven {
name 'sonatype-snapshots'
url 'http://oss.sonatype.org/content/repositories/snapshots/'
}
String luceneVersion = VersionProperties.lucene
if (luceneVersion.contains('-snapshot')) {
// extract the revision number from the version with a regex matcher
String revision = (luceneVersion =~ /\w+-snapshot-(\d+)/)[0][1]
repos.maven {
name 'lucene-snapshots'
url "http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/${revision}"
}
}
}
/** Adds compiler settings to the project */ /** Adds compiler settings to the project */
static void configureCompile(Project project) { static void configureCompile(Project project) {
project.afterEvaluate { project.afterEvaluate {
@ -91,8 +112,8 @@ class BuildPlugin implements Plugin<Project> {
project.afterEvaluate { project.afterEvaluate {
project.tasks.withType(Jar) { Jar jarTask -> project.tasks.withType(Jar) { Jar jarTask ->
manifest { manifest {
attributes('X-Compile-Elasticsearch-Version': ElasticsearchProperties.version, attributes('X-Compile-Elasticsearch-Version': VersionProperties.elasticsearch,
'X-Compile-Lucene-Version': ElasticsearchProperties.luceneVersion) 'X-Compile-Lucene-Version': VersionProperties.lucene)
} }
} }
} }

View File

@ -19,19 +19,23 @@
package org.elasticsearch.gradle package org.elasticsearch.gradle
/** /**
* Accessor for properties about the version of elasticsearch this was built with. * Accessor for shared dependency versions used by elasticsearch, namely the elasticsearch and lucene versions.
*/ */
class ElasticsearchProperties { class VersionProperties {
static final String version static final String elasticsearch
static final String luceneVersion static final String lucene
static final Map<String, String> versions = new HashMap<>()
static { static {
Properties props = new Properties() Properties props = new Properties()
InputStream propsStream = ElasticsearchProperties.class.getResourceAsStream('/elasticsearch.properties') InputStream propsStream = VersionProperties.class.getResourceAsStream('/version.properties')
if (propsStream == null) { if (propsStream == null) {
throw new RuntimeException('/elasticsearch.properties resource missing') throw new RuntimeException('/version.properties resource missing')
} }
props.load(propsStream) props.load(propsStream)
version = props.getProperty('version') elasticsearch = props.getProperty('elasticsearch')
luceneVersion = props.getProperty('luceneVersion') lucene = props.getProperty('lucene')
for (String property : props.stringPropertyNames()) {
versions.put(property, props.getProperty(property))
}
} }
} }

View File

@ -20,7 +20,6 @@ package org.elasticsearch.gradle.plugin
import nebula.plugin.extraconfigurations.ProvidedBasePlugin import nebula.plugin.extraconfigurations.ProvidedBasePlugin
import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.ElasticsearchProperties
import org.elasticsearch.gradle.test.RestIntegTestTask import org.elasticsearch.gradle.test.RestIntegTestTask
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
@ -64,20 +63,18 @@ class PluginBuildPlugin extends BuildPlugin {
} }
static void configureDependencies(Project project) { static void configureDependencies(Project project) {
String elasticsearchVersion = ElasticsearchProperties.version
project.dependencies { project.dependencies {
provided "org.elasticsearch:elasticsearch:${elasticsearchVersion}" provided "org.elasticsearch:elasticsearch:${project.versions.elasticsearch}"
testCompile "org.elasticsearch:test-framework:${elasticsearchVersion}" testCompile "org.elasticsearch:test-framework:${project.versions.elasticsearch}"
// we "upgrade" these optional deps to provided for plugins, since they will run // we "upgrade" these optional deps to provided for plugins, since they will run
// with a full elasticsearch server that includes optional deps // with a full elasticsearch server that includes optional deps
// TODO: remove duplication of version here with core... provided "com.spatial4j:spatial4j:${project.versions.spatial4j}"
provided 'com.spatial4j:spatial4j:0.4.1' provided "com.vividsolutions:jts:${project.versions.jts}"
provided 'com.vividsolutions:jts:1.13' provided "com.github.spullara.mustache.java:compiler:${project.versions.mustache}"
provided 'com.github.spullara.mustache.java:compiler:0.9.1' provided "log4j:log4j:${project.versions.log4j}"
provided "log4j:log4j:1.2.17" provided "log4j:apache-log4j-extras:${project.versions.log4j}"
provided "log4j:apache-log4j-extras:1.2.17" provided "org.slf4j:slf4j-api:${project.versions.slf4j}"
provided "org.slf4j:slf4j-api:1.6.2" provided "net.java.dev.jna:jna:${project.versions.jna}"
provided 'net.java.dev.jna:jna:4.1.0'
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.elasticsearch.gradle.plugin package org.elasticsearch.gradle.plugin
import org.elasticsearch.gradle.ElasticsearchProperties import org.elasticsearch.gradle.VersionProperties
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Copy
@ -72,7 +72,7 @@ class PluginPropertiesTask extends Copy {
'name': extension.name, 'name': extension.name,
'description': extension.description, 'description': extension.description,
'version': extension.version, 'version': extension.version,
'elasticsearchVersion': ElasticsearchProperties.version, 'elasticsearchVersion': VersionProperties.elasticsearch,
'javaVersion': project.targetCompatibility as String, 'javaVersion': project.targetCompatibility as String,
'jvm': extension.jvm as String, 'jvm': extension.jvm as String,
'site': extension.site as String, 'site': extension.site as String,

View File

@ -23,7 +23,7 @@ import org.gradle.internal.jvm.Jvm
import java.nio.file.Paths import java.nio.file.Paths
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.ElasticsearchProperties import org.elasticsearch.gradle.VersionProperties
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.GradleException import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
@ -56,7 +56,7 @@ class ClusterFormationTasks {
/** Adds a dependency on the given distribution */ /** Adds a dependency on the given distribution */
static void configureDistributionDependency(Project project, String distro) { static void configureDistributionDependency(Project project, String distro) {
String elasticsearchVersion = ElasticsearchProperties.version String elasticsearchVersion = VersionProperties.elasticsearch
String packaging = distro == 'tar' ? 'tar.gz' : distro String packaging = distro == 'tar' ? 'tar.gz' : distro
project.configurations { project.configurations {
elasticsearchDistro elasticsearchDistro
@ -336,7 +336,7 @@ class ClusterFormationTasks {
switch (distro) { switch (distro) {
case 'zip': case 'zip':
case 'tar': case 'tar':
path = "elasticsearch-${ElasticsearchProperties.version}" path = "elasticsearch-${VersionProperties.elasticsearch}"
break; break;
default: default:
throw new InvalidUserDataException("Unknown distribution: ${distro}") throw new InvalidUserDataException("Unknown distribution: ${distro}")

View File

@ -18,7 +18,7 @@
*/ */
package org.elasticsearch.gradle.test package org.elasticsearch.gradle.test
import org.elasticsearch.gradle.ElasticsearchProperties import org.elasticsearch.gradle.VersionProperties
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Copy
@ -38,7 +38,7 @@ class RestSpecHack {
restSpec restSpec
} }
project.dependencies { project.dependencies {
restSpec "org.elasticsearch:rest-api-spec:${ElasticsearchProperties.version}" restSpec "org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}"
} }
} }

View File

@ -21,7 +21,8 @@
package org.elasticsearch.gradle.test package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin
import org.elasticsearch.gradle.ElasticsearchProperties import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.VersionProperties
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
@ -31,6 +32,8 @@ class StandaloneTestBasePlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
BuildPlugin.configureRepositories(project)
project.pluginManager.apply(JavaBasePlugin) project.pluginManager.apply(JavaBasePlugin)
project.pluginManager.apply(RandomizedTestingPlugin) project.pluginManager.apply(RandomizedTestingPlugin)
@ -42,7 +45,7 @@ class StandaloneTestBasePlugin implements Plugin<Project> {
test test
} }
project.dependencies { project.dependencies {
testCompile "org.elasticsearch:test-framework:${ElasticsearchProperties.version}" testCompile "org.elasticsearch:test-framework:${VersionProperties.elasticsearch}"
} }
project.eclipse { project.eclipse {

View File

@ -21,7 +21,6 @@ package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingTask import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.ElasticsearchProperties
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin

View File

@ -0,0 +1,17 @@
elasticsearch = 3.0.0-SNAPSHOT
lucene = 5.4.0-snapshot-1712973
# optional dependencies
spatial4j = 0.5
jts = 1.13
mustache = 0.9.1
jackson = 2.6.2
log4j = 1.2.17
slf4j = 1.6.2
jna = 4.1.0
# test dependencies
randomizedrunner = 2.2.0
junit = 4.11
httpclient = 4.3.6

View File

@ -27,12 +27,6 @@ apply plugin: 'nebula.optional-base'
archivesBaseName = 'elasticsearch' archivesBaseName = 'elasticsearch'
versions << [
jackson: '2.6.2',
log4j: '1.2.17',
slf4j: '1.6.2'
]
dependencies { dependencies {
// lucene // lucene
@ -76,18 +70,18 @@ dependencies {
compile 'org.hdrhistogram:HdrHistogram:2.1.6' compile 'org.hdrhistogram:HdrHistogram:2.1.6'
// lucene spatial // lucene spatial
compile 'com.spatial4j:spatial4j:0.5', optional compile "com.spatial4j:spatial4j:${versions.spatial4j}", optional
compile 'com.vividsolutions:jts:1.13', optional compile "com.vividsolutions:jts:${versions.jts}", optional
// templating // templating
compile 'com.github.spullara.mustache.java:compiler:0.9.1', optional compile "com.github.spullara.mustache.java:compiler:${versions.mustache}", optional
// logging // logging
compile "log4j:log4j:${versions.log4j}", optional compile "log4j:log4j:${versions.log4j}", optional
compile "log4j:apache-log4j-extras:${versions.log4j}", optional compile "log4j:apache-log4j-extras:${versions.log4j}", optional
compile "org.slf4j:slf4j-api:${versions.slf4j}", optional compile "org.slf4j:slf4j-api:${versions.slf4j}", optional
compile 'net.java.dev.jna:jna:4.1.0', optional compile "net.java.dev.jna:jna:${versions.jna}", optional
if (isEclipse == false || project.path == "${projectsPrefix}:core-tests") { if (isEclipse == false || project.path == "${projectsPrefix}:core-tests") {
testCompile("org.elasticsearch:test-framework:${version}") { testCompile("org.elasticsearch:test-framework:${version}") {

View File

@ -1,3 +0,0 @@
group=org.elasticsearch
version=3.0.0-SNAPSHOT
luceneVersion=5.4.0-snapshot-1712973

View File

@ -17,8 +17,6 @@
* under the License. * under the License.
*/ */
import org.elasticsearch.gradle.ElasticsearchProperties
esplugin { esplugin {
name 'mapper-attachments' name 'mapper-attachments'
description 'The mapper attachments plugin adds the attachment type to Elasticsearch using Apache Tika.' description 'The mapper attachments plugin adds the attachment type to Elasticsearch using Apache Tika.'

View File

@ -24,7 +24,7 @@ apply plugin: 'com.bmuschko.nexus'
dependencies { dependencies {
compile "org.elasticsearch:elasticsearch:${version}" compile "org.elasticsearch:elasticsearch:${version}"
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
compile(group: 'junit', name: 'junit', version: '4.11') { compile("junit:junit:${versions.junit}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core' exclude group: 'org.hamcrest', module: 'hamcrest-core'
} }
compile("org.apache.lucene:lucene-test-framework:${versions.lucene}") { compile("org.apache.lucene:lucene-test-framework:${versions.lucene}") {