diff --git a/build.gradle b/build.gradle index 3027dade1a7..8218d49fd68 100644 --- a/build.gradle +++ b/build.gradle @@ -231,6 +231,23 @@ subprojects { } } + /* + * Gradle only resolve project substitutions during dependency resolution but + * we sometimes want to do the resolution at other times. This creates a + * convenient method we can call to do it. + */ + ext.dependencyToProject = { Dependency dep -> + if (dep instanceof ProjectDependency) { + return dep.dependencyProject + } else { + String substitution = projectSubstitutions.get("${dep.group}:${dep.name}:${dep.version}") + if (substitution != null) { + return findProject(substitution) + } + return null + } + } + project.afterEvaluate { configurations.all { resolutionStrategy.dependencySubstitution { DependencySubstitutions subs -> @@ -249,11 +266,11 @@ subprojects { Closure sortClosure = { a, b -> b.group <=> a.group } Closure depJavadocClosure = { dep -> if (dep.group != null && dep.group.startsWith('org.elasticsearch')) { - String substitution = project.ext.projectSubstitutions.get("${dep.group}:${dep.name}:${dep.version}") - if (substitution != null) { - project.javadoc.dependsOn substitution + ':javadoc' + Project upstreamProject = dependencyToProject(dep) + if (upstreamProject != null) { + project.javadoc.dependsOn "${upstreamProject.path}:javadoc" String artifactPath = dep.group.replaceAll('\\.', '/') + '/' + dep.name.replaceAll('\\.', '/') + '/' + dep.version - project.javadoc.options.linksOffline artifactsHost + "/javadoc/" + artifactPath, "${project.project(substitution).buildDir}/docs/javadoc/" + project.javadoc.options.linksOffline artifactsHost + "/javadoc/" + artifactPath, "${upstreamProject.buildDir}/docs/javadoc/" } } } @@ -275,17 +292,7 @@ gradle.projectsEvaluated { } configurations.all { dependencies.all { Dependency dep -> - Project upstreamProject = null - if (dep instanceof ProjectDependency) { - upstreamProject = dep.dependencyProject - } else { - // gradle doesn't apply substitutions until resolve time, so they won't - // show up as a ProjectDependency above - String substitution = projectSubstitutions.get("${dep.group}:${dep.name}:${dep.version}") - if (substitution != null) { - upstreamProject = findProject(substitution) - } - } + Project upstreamProject = dependencyToProject(dep) if (upstreamProject != null) { if (project.path == upstreamProject.path) { // TODO: distribution integ tests depend on themselves (!), fix that diff --git a/libs/build.gradle b/libs/build.gradle index e69de29bb2d..78eb9388624 100644 --- a/libs/build.gradle +++ b/libs/build.gradle @@ -0,0 +1,46 @@ +/* + * 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. + */ + +subprojects { + /* + * All subprojects are java projects using Elasticsearch's standard build + * tools. + */ + apply plugin: 'elasticsearch.build' + + /* + * Subprojects may depend on the "core" lib but may not depend on any + * other libs. This keeps are dependencies simpler. + */ + project.afterEvaluate { + configurations.all { Configuration conf -> + dependencies.all { Dependency dep -> + Project depProject = dependencyToProject(dep) + if (depProject != null + && false == depProject.path.equals(':libs:elasticsearch-core') + && depProject.path.startsWith(':libs')) { + throw new InvalidUserDataException("projects in :libs " + + "may not depend on other projects libs except " + + ":libs:elasticsearch-core but " + + "${project.path} depends on ${depProject.path}") + } + } + } + } +} diff --git a/libs/elasticsearch-core/build.gradle b/libs/elasticsearch-core/build.gradle index 26a232664ad..d374e7a8486 100644 --- a/libs/elasticsearch-core/build.gradle +++ b/libs/elasticsearch-core/build.gradle @@ -19,7 +19,6 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks * under the License. */ -apply plugin: 'elasticsearch.build' apply plugin: 'nebula.optional-base' apply plugin: 'nebula.maven-base-publish' apply plugin: 'nebula.maven-scm' diff --git a/libs/elasticsearch-nio/build.gradle b/libs/elasticsearch-nio/build.gradle index 247edeeed35..a32a860a628 100644 --- a/libs/elasticsearch-nio/build.gradle +++ b/libs/elasticsearch-nio/build.gradle @@ -19,7 +19,6 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks -apply plugin: 'elasticsearch.build' apply plugin: 'nebula.maven-base-publish' apply plugin: 'nebula.maven-scm' @@ -39,7 +38,7 @@ dependencies { testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testCompile "junit:junit:${versions.junit}" testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}" - + if (isEclipse == false || project.path == ":libs:elasticsearch-nio-tests") { testCompile("org.elasticsearch.test:framework:${version}") { exclude group: 'org.elasticsearch', module: 'elasticsearch-nio' diff --git a/libs/grok/build.gradle b/libs/grok/build.gradle index c91312cf9e8..61437be6aff 100644 --- a/libs/grok/build.gradle +++ b/libs/grok/build.gradle @@ -19,8 +19,6 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks * under the License. */ -apply plugin: 'elasticsearch.build' - archivesBaseName = 'elasticsearch-grok' dependencies { diff --git a/libs/plugin-classloader/build.gradle b/libs/plugin-classloader/build.gradle index 1bc7fc90272..d6af6600d34 100644 --- a/libs/plugin-classloader/build.gradle +++ b/libs/plugin-classloader/build.gradle @@ -17,8 +17,6 @@ * under the License. */ -apply plugin: 'elasticsearch.build' - test.enabled = false // test depend on ES core... diff --git a/libs/secure-sm/build.gradle b/libs/secure-sm/build.gradle index 607230753b5..93fdfd01c8f 100644 --- a/libs/secure-sm/build.gradle +++ b/libs/secure-sm/build.gradle @@ -19,7 +19,6 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks -apply plugin: 'elasticsearch.build' apply plugin: 'nebula.maven-base-publish' apply plugin: 'nebula.maven-scm'