diff --git a/build-tools-internal/src/main/groovy/elasticsearch.all-projects.gradle b/build-tools-internal/src/main/groovy/elasticsearch.all-projects.gradle new file mode 100644 index 0000000000000..5d19cbd171369 --- /dev/null +++ b/build-tools-internal/src/main/groovy/elasticsearch.all-projects.gradle @@ -0,0 +1,132 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import org.gradle.plugins.ide.eclipse.model.AccessRule + +import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure +import org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin +import org.gradle.plugins.ide.eclipse.model.AccessRule +import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin +import org.elasticsearch.gradle.internal.ResolveAllDependencies +import org.elasticsearch.gradle.VersionProperties + +description = "Elasticsearch subproject " + getPath(); +// common maven publishing configuration +group = "org.elasticsearch" +version = VersionProperties.getElasticsearch() + + +// enabled by default +ext.bwc_tests_enabled = true + +tasks.register('resolveAllDependencies', ResolveAllDependencies) { + def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"] + configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false } + resolveJavaToolChain = true + if (project.path.contains("fixture")) { + dependsOn tasks.withType(ComposePull) + } + if (project.path.contains(":distribution:docker")) { + enabled = false + } + if (project.path.contains(":libs:cli")) { + // ensure we resolve p2 dependencies for the spotless eclipse formatter + dependsOn "spotlessJavaCheck" + } +} + +plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded { + project.dependencies { + compileOnly project(":server") + testImplementation project(":test:framework") + } +} + + +/* + * Allow accessing com/sun/net/httpserver in projects that have + * configured forbidden apis to allow it. + */ +plugins.withType(ForbiddenApisPlugin) { + eclipse.classpath.file.whenMerged { classpath -> + if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) { + classpath.entries + .findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") } + .each { + it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*")) + } + } + } +} + +ext.withReleaseBuild = { Closure config -> + if(buildParams.snapshotBuild == false) { + config.call() + } +} + +plugins.withId('lifecycle-base') { + if (project.path.startsWith(":x-pack:")) { + if (project.path.contains("security") || project.path.contains(":ml")) { + tasks.register('checkPart4') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } + } else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) { + tasks.register('checkPart3') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } + } else if (project.path.contains("multi-node")) { + tasks.register('checkPart5') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } + } else { + tasks.register('checkPart2') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } + } + } else { + tasks.register('checkPart1') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } + } + tasks.register('functionalTests') { + dependsOn 'check' + withReleaseBuild { + dependsOn 'assemble' + } + } +} + +/* + * Remove assemble/dependenciesInfo on all qa projects because we don't + * need to publish artifacts for them. + */ +if (project.name.equals('qa') || project.path.contains(':qa:')) { + maybeConfigure(project.tasks, 'assemble') { + it.enabled = false + } + maybeConfigure(project.tasks, 'dependenciesInfo') { + it.enabled = false + } +} diff --git a/build-tools-internal/src/main/groovy/elasticsearch.base.gradle b/build-tools-internal/src/main/groovy/elasticsearch.base.gradle deleted file mode 100644 index f7b7ff179aaff..0000000000000 --- a/build-tools-internal/src/main/groovy/elasticsearch.base.gradle +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import org.elasticsearch.gradle.VersionProperties - -project.setDescription("Elasticsearch subproject " + project.getPath()); -// common maven publishing configuration -project.setGroup("org.elasticsearch"); -project.setVersion(VersionProperties.getElasticsearch()) diff --git a/build-tools-internal/src/main/groovy/elasticsearch.forbidden-dependencies.gradle b/build-tools-internal/src/main/groovy/elasticsearch.forbidden-dependencies.gradle index b52692e192ebb..60d14c52cab2e 100644 --- a/build-tools-internal/src/main/groovy/elasticsearch.forbidden-dependencies.gradle +++ b/build-tools-internal/src/main/groovy/elasticsearch.forbidden-dependencies.gradle @@ -22,13 +22,12 @@ Closure checkDeps = { Configuration configuration -> } } -subprojects { - if (project.path.startsWith(':test:fixtures:') || project.path.equals(':build-tools')) { - // fixtures are allowed to use whatever dependencies they want... - return - } - pluginManager.withPlugin('java') { - checkDeps(configurations.compileClasspath) - checkDeps(configurations.testCompileClasspath) - } +if (project.path.startsWith(':test:fixtures:') || project.path.equals(':build-tools')) { + // fixtures are allowed to use whatever dependencies they want... + return +} + +pluginManager.withPlugin('java') { + checkDeps(configurations.compileClasspath) + checkDeps(configurations.testCompileClasspath) } diff --git a/build.gradle b/build.gradle index 1f8f11fe05110..0597034ad53e3 100644 --- a/build.gradle +++ b/build.gradle @@ -8,22 +8,15 @@ */ -import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin -import com.avast.gradle.dockercompose.tasks.ComposePull import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper -import org.elasticsearch.gradle.DistributionDownloadPlugin import org.elasticsearch.gradle.Version -import org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin -import org.elasticsearch.gradle.internal.ResolveAllDependencies import org.elasticsearch.gradle.util.GradleUtils -import org.gradle.plugins.ide.eclipse.model.AccessRule import java.nio.file.Files import static java.nio.file.StandardCopyOption.REPLACE_EXISTING -import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure buildscript { repositories { @@ -225,162 +218,17 @@ tasks.register("verifyVersions") { // longer used for that purpose, but instead a way to run only functional tests. We should // rework the functionalTests task to be more explicit about which tasks it wants to run // so that that this flag is no longer needed. -boolean bwc_tests_enabled = true +boolean bwcTestsEnabled = true if (project.gradle.startParameter.taskNames.any { it.startsWith("checkPart") || it == 'functionalTests' }) { // Disable BWC tests for checkPart* tasks and platform support tests as it's expected that this will run on it's own check - bwc_tests_enabled = false -} - -subprojects { proj -> - apply plugin: 'elasticsearch.base' + bwcTestsEnabled = false } allprojects { - // We disable this plugin for now till we shaked out the issues we see - // e.g. see https://github.com/elastic/elasticsearch/issues/72169 - // apply plugin:'elasticsearch.internal-test-rerun' - - plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded { - project.dependencies { - compileOnly project(":server") - testImplementation project(":test:framework") - } - } - - ext.bwc_tests_enabled = bwc_tests_enabled - - // eclipse configuration - apply plugin: 'elasticsearch.eclipse' - - /* - * Allow accessing com/sun/net/httpserver in projects that have - * configured forbidden apis to allow it. - */ - plugins.withType(ForbiddenApisPlugin) { - eclipse.classpath.file.whenMerged { classpath -> - if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) { - classpath.entries - .findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") } - .each { - it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*")) - } - } - } - } - - tasks.register('resolveAllDependencies', ResolveAllDependencies) { - def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"] - configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false } - resolveJavaToolChain = true - if (project.path.contains("fixture")) { - dependsOn tasks.withType(ComposePull) - } - if (project.path.contains(":distribution:docker")) { - enabled = false - } - if (project.path.contains(":libs:cli")) { - // ensure we resolve p2 dependencies for the spotless eclipse formatter - dependsOn "spotlessJavaCheck" - } - } - - ext.withReleaseBuild = { Closure config -> - if(buildParams.snapshotBuild == false) { - config.call() - } - } - - plugins.withId('lifecycle-base') { - if (project.path.startsWith(":x-pack:")) { - if (project.path.contains("security") || project.path.contains(":ml")) { - tasks.register('checkPart4') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) { - tasks.register('checkPart3') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } else if (project.path.contains("multi-node")) { - tasks.register('checkPart5') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } else { - tasks.register('checkPart2') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } - } else { - tasks.register('checkPart1') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } - tasks.register('functionalTests') { - dependsOn 'check' - withReleaseBuild { - dependsOn 'assemble' - } - } - } - - /* - * Remove assemble/dependenciesInfo on all qa projects because we don't - * need to publish artifacts for them. - */ - if (project.name.equals('qa') || project.path.contains(':qa:')) { - maybeConfigure(project.tasks, 'assemble') { - it.enabled = false - } - maybeConfigure(project.tasks, 'dependenciesInfo') { - it.enabled = false - } - } - - project.afterEvaluate { - // Ensure similar tasks in dependent projects run first. The projectsEvaluated here is - // important because, while dependencies.all will pickup future dependencies, - // it is not necessarily true that the task exists in both projects at the time - // the dependency is added. - if (project.path == ':test:framework') { - // :test:framework:test cannot run before and after :server:test - return - } - tasks.matching { it.name.equals('integTest') }.configureEach { integTestTask -> - integTestTask.mustRunAfter tasks.matching { it.name.equals("test") } - } - -/* configurations.matching { it.canBeResolved }.all { Configuration configuration -> - dependencies.matching { it instanceof ProjectDependency }.all { ProjectDependency dep -> - Project upstreamProject = dep.dependencyProject - if (project.path != upstreamProject?.path) { - for (String taskName : ['test', 'integTest']) { - project.tasks.matching { it.name == taskName }.configureEach { task -> - task.shouldRunAfter(upstreamProject.tasks.matching { upStreamTask -> upStreamTask.name == taskName }) - } - } - } - } - }*/ - } - - apply plugin: 'elasticsearch.formatting' + // bwc_tests_enabled is a ext flag defined in 'elasticsearch.all-projects.gradle' + bwc_tests_enabled = bwcTestsEnabled } - tasks.register("verifyBwcTestsEnabled") { doLast { if (bwc_tests_enabled == false) { @@ -412,24 +260,6 @@ tasks.named("wrapper").configure { } } -gradle.projectsEvaluated { - // Having the same group and name for distinct projects causes Gradle to consider them equal when resolving - // dependencies leading to hard to debug failures. Run a check across all project to prevent this from happening. - // see: https://github.com/gradle/gradle/issues/847 - Map coordsToProject = [:] - project.allprojects.forEach { p -> - String coords = "${p.group}:${p.name}" - if (false == coordsToProject.putIfAbsent(coords, p)) { - throw new GradleException( - "Detected that two projects: ${p.path} and ${coordsToProject[coords].path} " + - "have the same name and group: ${coords}. " + - "This doesn't currently work correctly in Gradle, see: " + - "https://github.com/gradle/gradle/issues/847" - ) - } - } -} - tasks.named("validateChangelogs").configure { def triggeredTaskNames = gradle.startParameter.taskNames onlyIf { diff --git a/settings.gradle b/settings.gradle index a6b5367591ee2..e8d8bfb5f7d38 100644 --- a/settings.gradle +++ b/settings.gradle @@ -168,3 +168,12 @@ if (extraProjects.exists()) { addSubProjects('', extraProjectDir) } } + +gradle.lifecycle.beforeProject { + apply plugin:"elasticsearch.all-projects" + + // unfortunately we cannot nest script plugins + apply plugin: 'elasticsearch.eclipse' + apply plugin: 'elasticsearch.formatting' + apply plugin: 'elasticsearch.forbidden-dependencies' +}