Skip to content

Commit b6d3ee1

Browse files
committed
[Gradle] Rework all project configuration to better support Isolated Projects
- do not reference Project#plugins in allprojects - reduce plugin application in allprojects - apply common configuration via gradle.lifecycle.beforeProject; More cleanup Move more plugins out of allprojects Cleanup forbidden dependencies plugin usage
1 parent 4269c73 commit b6d3ee1

File tree

5 files changed

+153
-198
lines changed

5 files changed

+153
-198
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import org.gradle.plugins.ide.eclipse.model.AccessRule
11+
12+
import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
13+
import org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin
14+
import org.gradle.plugins.ide.eclipse.model.AccessRule
15+
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
16+
import org.elasticsearch.gradle.internal.ResolveAllDependencies
17+
import org.elasticsearch.gradle.VersionProperties
18+
19+
description = "Elasticsearch subproject " + getPath();
20+
// common maven publishing configuration
21+
group = "org.elasticsearch"
22+
version = VersionProperties.getElasticsearch()
23+
24+
25+
// enabled by default
26+
ext.bwc_tests_enabled = true
27+
28+
tasks.register('resolveAllDependencies', ResolveAllDependencies) {
29+
def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"]
30+
configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false }
31+
resolveJavaToolChain = true
32+
if (project.path.contains("fixture")) {
33+
dependsOn tasks.withType(ComposePull)
34+
}
35+
if (project.path.contains(":distribution:docker")) {
36+
enabled = false
37+
}
38+
if (project.path.contains(":libs:cli")) {
39+
// ensure we resolve p2 dependencies for the spotless eclipse formatter
40+
dependsOn "spotlessJavaCheck"
41+
}
42+
}
43+
44+
plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded {
45+
project.dependencies {
46+
compileOnly project(":server")
47+
testImplementation project(":test:framework")
48+
}
49+
}
50+
51+
52+
/*
53+
* Allow accessing com/sun/net/httpserver in projects that have
54+
* configured forbidden apis to allow it.
55+
*/
56+
plugins.withType(ForbiddenApisPlugin) {
57+
eclipse.classpath.file.whenMerged { classpath ->
58+
if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) {
59+
classpath.entries
60+
.findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") }
61+
.each {
62+
it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*"))
63+
}
64+
}
65+
}
66+
}
67+
68+
ext.withReleaseBuild = { Closure config ->
69+
if(buildParams.snapshotBuild == false) {
70+
config.call()
71+
}
72+
}
73+
74+
plugins.withId('lifecycle-base') {
75+
if (project.path.startsWith(":x-pack:")) {
76+
if (project.path.contains("security") || project.path.contains(":ml")) {
77+
tasks.register('checkPart4') {
78+
dependsOn 'check'
79+
withReleaseBuild {
80+
dependsOn 'assemble'
81+
}
82+
}
83+
} else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) {
84+
tasks.register('checkPart3') {
85+
dependsOn 'check'
86+
withReleaseBuild {
87+
dependsOn 'assemble'
88+
}
89+
}
90+
} else if (project.path.contains("multi-node")) {
91+
tasks.register('checkPart5') {
92+
dependsOn 'check'
93+
withReleaseBuild {
94+
dependsOn 'assemble'
95+
}
96+
}
97+
} else {
98+
tasks.register('checkPart2') {
99+
dependsOn 'check'
100+
withReleaseBuild {
101+
dependsOn 'assemble'
102+
}
103+
}
104+
}
105+
} else {
106+
tasks.register('checkPart1') {
107+
dependsOn 'check'
108+
withReleaseBuild {
109+
dependsOn 'assemble'
110+
}
111+
}
112+
}
113+
tasks.register('functionalTests') {
114+
dependsOn 'check'
115+
withReleaseBuild {
116+
dependsOn 'assemble'
117+
}
118+
}
119+
}
120+
121+
/*
122+
* Remove assemble/dependenciesInfo on all qa projects because we don't
123+
* need to publish artifacts for them.
124+
*/
125+
if (project.name.equals('qa') || project.path.contains(':qa:')) {
126+
maybeConfigure(project.tasks, 'assemble') {
127+
it.enabled = false
128+
}
129+
maybeConfigure(project.tasks, 'dependenciesInfo') {
130+
it.enabled = false
131+
}
132+
}

build-tools-internal/src/main/groovy/elasticsearch.base.gradle

Lines changed: 0 additions & 15 deletions
This file was deleted.

build-tools-internal/src/main/groovy/elasticsearch.forbidden-dependencies.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ Closure checkDeps = { Configuration configuration ->
2222
}
2323
}
2424

25-
subprojects {
26-
if (project.path.startsWith(':test:fixtures:') || project.path.equals(':build-tools')) {
27-
// fixtures are allowed to use whatever dependencies they want...
28-
return
29-
}
30-
pluginManager.withPlugin('java') {
31-
checkDeps(configurations.compileClasspath)
32-
checkDeps(configurations.testCompileClasspath)
33-
}
25+
if (project.path.startsWith(':test:fixtures:') || project.path.equals(':build-tools')) {
26+
// fixtures are allowed to use whatever dependencies they want...
27+
return
28+
}
29+
30+
pluginManager.withPlugin('java') {
31+
checkDeps(configurations.compileClasspath)
32+
checkDeps(configurations.testCompileClasspath)
3433
}

build.gradle

Lines changed: 4 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@
88
*/
99

1010

11-
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
12-
import com.avast.gradle.dockercompose.tasks.ComposePull
1311
import com.fasterxml.jackson.databind.JsonNode
1412
import com.fasterxml.jackson.databind.ObjectMapper
1513

16-
import org.elasticsearch.gradle.DistributionDownloadPlugin
1714
import org.elasticsearch.gradle.Version
18-
import org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin
19-
import org.elasticsearch.gradle.internal.ResolveAllDependencies
2015
import org.elasticsearch.gradle.util.GradleUtils
21-
import org.gradle.plugins.ide.eclipse.model.AccessRule
2216

2317
import java.nio.file.Files
2418

2519
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
26-
import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
2720

2821
buildscript {
2922
repositories {
@@ -225,162 +218,17 @@ tasks.register("verifyVersions") {
225218
// longer used for that purpose, but instead a way to run only functional tests. We should
226219
// rework the functionalTests task to be more explicit about which tasks it wants to run
227220
// so that that this flag is no longer needed.
228-
boolean bwc_tests_enabled = true
221+
boolean bwcTestsEnabled = true
229222
if (project.gradle.startParameter.taskNames.any { it.startsWith("checkPart") || it == 'functionalTests' }) {
230223
// Disable BWC tests for checkPart* tasks and platform support tests as it's expected that this will run on it's own check
231-
bwc_tests_enabled = false
232-
}
233-
234-
subprojects { proj ->
235-
apply plugin: 'elasticsearch.base'
224+
bwcTestsEnabled = false
236225
}
237226

238227
allprojects {
239-
// We disable this plugin for now till we shaked out the issues we see
240-
// e.g. see https://github.com/elastic/elasticsearch/issues/72169
241-
// apply plugin:'elasticsearch.internal-test-rerun'
242-
243-
plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded {
244-
project.dependencies {
245-
compileOnly project(":server")
246-
testImplementation project(":test:framework")
247-
}
248-
}
249-
250-
ext.bwc_tests_enabled = bwc_tests_enabled
251-
252-
// eclipse configuration
253-
apply plugin: 'elasticsearch.eclipse'
254-
255-
/*
256-
* Allow accessing com/sun/net/httpserver in projects that have
257-
* configured forbidden apis to allow it.
258-
*/
259-
plugins.withType(ForbiddenApisPlugin) {
260-
eclipse.classpath.file.whenMerged { classpath ->
261-
if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) {
262-
classpath.entries
263-
.findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") }
264-
.each {
265-
it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*"))
266-
}
267-
}
268-
}
269-
}
270-
271-
tasks.register('resolveAllDependencies', ResolveAllDependencies) {
272-
def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"]
273-
configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false }
274-
resolveJavaToolChain = true
275-
if (project.path.contains("fixture")) {
276-
dependsOn tasks.withType(ComposePull)
277-
}
278-
if (project.path.contains(":distribution:docker")) {
279-
enabled = false
280-
}
281-
if (project.path.contains(":libs:cli")) {
282-
// ensure we resolve p2 dependencies for the spotless eclipse formatter
283-
dependsOn "spotlessJavaCheck"
284-
}
285-
}
286-
287-
ext.withReleaseBuild = { Closure config ->
288-
if(buildParams.snapshotBuild == false) {
289-
config.call()
290-
}
291-
}
292-
293-
plugins.withId('lifecycle-base') {
294-
if (project.path.startsWith(":x-pack:")) {
295-
if (project.path.contains("security") || project.path.contains(":ml")) {
296-
tasks.register('checkPart4') {
297-
dependsOn 'check'
298-
withReleaseBuild {
299-
dependsOn 'assemble'
300-
}
301-
}
302-
} else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) {
303-
tasks.register('checkPart3') {
304-
dependsOn 'check'
305-
withReleaseBuild {
306-
dependsOn 'assemble'
307-
}
308-
}
309-
} else if (project.path.contains("multi-node")) {
310-
tasks.register('checkPart5') {
311-
dependsOn 'check'
312-
withReleaseBuild {
313-
dependsOn 'assemble'
314-
}
315-
}
316-
} else {
317-
tasks.register('checkPart2') {
318-
dependsOn 'check'
319-
withReleaseBuild {
320-
dependsOn 'assemble'
321-
}
322-
}
323-
}
324-
} else {
325-
tasks.register('checkPart1') {
326-
dependsOn 'check'
327-
withReleaseBuild {
328-
dependsOn 'assemble'
329-
}
330-
}
331-
}
332-
tasks.register('functionalTests') {
333-
dependsOn 'check'
334-
withReleaseBuild {
335-
dependsOn 'assemble'
336-
}
337-
}
338-
}
339-
340-
/*
341-
* Remove assemble/dependenciesInfo on all qa projects because we don't
342-
* need to publish artifacts for them.
343-
*/
344-
if (project.name.equals('qa') || project.path.contains(':qa:')) {
345-
maybeConfigure(project.tasks, 'assemble') {
346-
it.enabled = false
347-
}
348-
maybeConfigure(project.tasks, 'dependenciesInfo') {
349-
it.enabled = false
350-
}
351-
}
352-
353-
project.afterEvaluate {
354-
// Ensure similar tasks in dependent projects run first. The projectsEvaluated here is
355-
// important because, while dependencies.all will pickup future dependencies,
356-
// it is not necessarily true that the task exists in both projects at the time
357-
// the dependency is added.
358-
if (project.path == ':test:framework') {
359-
// :test:framework:test cannot run before and after :server:test
360-
return
361-
}
362-
tasks.matching { it.name.equals('integTest') }.configureEach { integTestTask ->
363-
integTestTask.mustRunAfter tasks.matching { it.name.equals("test") }
364-
}
365-
366-
/* configurations.matching { it.canBeResolved }.all { Configuration configuration ->
367-
dependencies.matching { it instanceof ProjectDependency }.all { ProjectDependency dep ->
368-
Project upstreamProject = dep.dependencyProject
369-
if (project.path != upstreamProject?.path) {
370-
for (String taskName : ['test', 'integTest']) {
371-
project.tasks.matching { it.name == taskName }.configureEach { task ->
372-
task.shouldRunAfter(upstreamProject.tasks.matching { upStreamTask -> upStreamTask.name == taskName })
373-
}
374-
}
375-
}
376-
}
377-
}*/
378-
}
379-
380-
apply plugin: 'elasticsearch.formatting'
228+
// bwc_tests_enabled is a ext flag defined in 'elasticsearch.all-projects.gradle'
229+
bwc_tests_enabled = bwcTestsEnabled
381230
}
382231

383-
384232
tasks.register("verifyBwcTestsEnabled") {
385233
doLast {
386234
if (bwc_tests_enabled == false) {
@@ -412,24 +260,6 @@ tasks.named("wrapper").configure {
412260
}
413261
}
414262

415-
gradle.projectsEvaluated {
416-
// Having the same group and name for distinct projects causes Gradle to consider them equal when resolving
417-
// dependencies leading to hard to debug failures. Run a check across all project to prevent this from happening.
418-
// see: https://github.com/gradle/gradle/issues/847
419-
Map coordsToProject = [:]
420-
project.allprojects.forEach { p ->
421-
String coords = "${p.group}:${p.name}"
422-
if (false == coordsToProject.putIfAbsent(coords, p)) {
423-
throw new GradleException(
424-
"Detected that two projects: ${p.path} and ${coordsToProject[coords].path} " +
425-
"have the same name and group: ${coords}. " +
426-
"This doesn't currently work correctly in Gradle, see: " +
427-
"https://github.com/gradle/gradle/issues/847"
428-
)
429-
}
430-
}
431-
}
432-
433263
tasks.named("validateChangelogs").configure {
434264
def triggeredTaskNames = gradle.startParameter.taskNames
435265
onlyIf {

settings.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,12 @@ if (extraProjects.exists()) {
168168
addSubProjects('', extraProjectDir)
169169
}
170170
}
171+
172+
gradle.lifecycle.beforeProject {
173+
apply plugin:"elasticsearch.all-projects"
174+
175+
// unfortunately we cannot nest script plugins
176+
apply plugin: 'elasticsearch.eclipse'
177+
apply plugin: 'elasticsearch.formatting'
178+
apply plugin: 'elasticsearch.forbidden-dependencies'
179+
}

0 commit comments

Comments
 (0)