Skip to content

Commit f353bf0

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;
1 parent 4269c73 commit f353bf0

File tree

3 files changed

+133
-161
lines changed

3 files changed

+133
-161
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
18+
// enabled by default
19+
ext.bwc_tests_enabled = true
20+
21+
tasks.register('resolveAllDependencies', ResolveAllDependencies) {
22+
def ignoredPrefixes = [DistributionDownloadPlugin.ES_DISTRO_CONFIG_PREFIX, "jdbcDriver"]
23+
configs = project.configurations.matching { config -> ignoredPrefixes.any { config.name.startsWith(it) } == false }
24+
resolveJavaToolChain = true
25+
if (project.path.contains("fixture")) {
26+
dependsOn tasks.withType(ComposePull)
27+
}
28+
if (project.path.contains(":distribution:docker")) {
29+
enabled = false
30+
}
31+
if (project.path.contains(":libs:cli")) {
32+
// ensure we resolve p2 dependencies for the spotless eclipse formatter
33+
dependsOn "spotlessJavaCheck"
34+
}
35+
}
36+
37+
plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded {
38+
project.dependencies {
39+
compileOnly project(":server")
40+
testImplementation project(":test:framework")
41+
}
42+
}
43+
44+
45+
/*
46+
* Allow accessing com/sun/net/httpserver in projects that have
47+
* configured forbidden apis to allow it.
48+
*/
49+
plugins.withType(ForbiddenApisPlugin) {
50+
eclipse.classpath.file.whenMerged { classpath ->
51+
if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) {
52+
classpath.entries
53+
.findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") }
54+
.each {
55+
it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*"))
56+
}
57+
}
58+
}
59+
}
60+
61+
ext.withReleaseBuild = { Closure config ->
62+
if(buildParams.snapshotBuild == false) {
63+
config.call()
64+
}
65+
}
66+
67+
plugins.withId('lifecycle-base') {
68+
if (project.path.startsWith(":x-pack:")) {
69+
if (project.path.contains("security") || project.path.contains(":ml")) {
70+
tasks.register('checkPart4') {
71+
dependsOn 'check'
72+
withReleaseBuild {
73+
dependsOn 'assemble'
74+
}
75+
}
76+
} else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) {
77+
tasks.register('checkPart3') {
78+
dependsOn 'check'
79+
withReleaseBuild {
80+
dependsOn 'assemble'
81+
}
82+
}
83+
} else if (project.path.contains("multi-node")) {
84+
tasks.register('checkPart5') {
85+
dependsOn 'check'
86+
withReleaseBuild {
87+
dependsOn 'assemble'
88+
}
89+
}
90+
} else {
91+
tasks.register('checkPart2') {
92+
dependsOn 'check'
93+
withReleaseBuild {
94+
dependsOn 'assemble'
95+
}
96+
}
97+
}
98+
} else {
99+
tasks.register('checkPart1') {
100+
dependsOn 'check'
101+
withReleaseBuild {
102+
dependsOn 'assemble'
103+
}
104+
}
105+
}
106+
tasks.register('functionalTests') {
107+
dependsOn 'check'
108+
withReleaseBuild {
109+
dependsOn 'assemble'
110+
}
111+
}
112+
}
113+
114+
/*
115+
* Remove assemble/dependenciesInfo on all qa projects because we don't
116+
* need to publish artifacts for them.
117+
*/
118+
if (project.name.equals('qa') || project.path.contains(':qa:')) {
119+
maybeConfigure(project.tasks, 'assemble') {
120+
it.enabled = false
121+
}
122+
maybeConfigure(project.tasks, 'dependenciesInfo') {
123+
it.enabled = false
124+
}
125+
}

build.gradle

Lines changed: 4 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -225,162 +225,23 @@ tasks.register("verifyVersions") {
225225
// longer used for that purpose, but instead a way to run only functional tests. We should
226226
// rework the functionalTests task to be more explicit about which tasks it wants to run
227227
// so that that this flag is no longer needed.
228-
boolean bwc_tests_enabled = true
228+
boolean bwcTestsEnabled = true
229229
if (project.gradle.startParameter.taskNames.any { it.startsWith("checkPart") || it == 'functionalTests' }) {
230230
// 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
231+
bwcTestsEnabled = false
232232
}
233233

234234
subprojects { proj ->
235235
apply plugin: 'elasticsearch.base'
236236
}
237237

238238
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
253239
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-
380240
apply plugin: 'elasticsearch.formatting'
241+
// bwc_tests_enabled is a ext flag defined in 'elasticsearch.all-projects.gradle'
242+
bwc_tests_enabled = bwcTestsEnabled
381243
}
382244

383-
384245
tasks.register("verifyBwcTestsEnabled") {
385246
doLast {
386247
if (bwc_tests_enabled == false) {
@@ -412,24 +273,6 @@ tasks.named("wrapper").configure {
412273
}
413274
}
414275

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-
433276
tasks.named("validateChangelogs").configure {
434277
def triggeredTaskNames = gradle.startParameter.taskNames
435278
onlyIf {

settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ if (extraProjects.exists()) {
168168
addSubProjects('', extraProjectDir)
169169
}
170170
}
171+
172+
gradle.lifecycle.beforeProject {
173+
apply plugin:"elasticsearch.all-projects"
174+
}

0 commit comments

Comments
 (0)