Skip to content

Commit 03e98e8

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 7519de6 commit 03e98e8

File tree

5 files changed

+247
-204
lines changed

5 files changed

+247
-204
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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+
if (project.path == ':') {
32+
resolveJavaToolChain = true
33+
34+
// ensure we have best possible caching of bwc builds
35+
dependsOn ":distribution:bwc:bugfix:buildBwcLinuxTar"
36+
dependsOn ":distribution:bwc:bugfix2:buildBwcLinuxTar"
37+
dependsOn ":distribution:bwc:bugfix3:buildBwcLinuxTar"
38+
dependsOn ":distribution:bwc:bugfix4:buildBwcLinuxTar"
39+
dependsOn ":distribution:bwc:bugfix5:buildBwcLinuxTar"
40+
dependsOn ":distribution:bwc:minor:buildBwcLinuxTar"
41+
dependsOn ":distribution:bwc:staged:buildBwcLinuxTar"
42+
dependsOn ":distribution:bwc:staged2:buildBwcLinuxTar"
43+
}
44+
if (project.path.contains("fixture")) {
45+
dependsOn tasks.withType(ComposePull)
46+
}
47+
if (project.path.contains(":distribution:docker")) {
48+
enabled = false
49+
}
50+
if (project.path.contains(":libs:cli")) {
51+
// ensure we resolve p2 dependencies for the spotless eclipse formatter
52+
dependsOn "spotlessJavaCheck"
53+
}
54+
}
55+
56+
plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded {
57+
project.dependencies {
58+
compileOnly project(":server")
59+
testImplementation project(":test:framework")
60+
}
61+
}
62+
63+
64+
/*
65+
* Allow accessing com/sun/net/httpserver in projects that have
66+
* configured forbidden apis to allow it.
67+
*/
68+
plugins.withType(ForbiddenApisPlugin) {
69+
eclipse.classpath.file.whenMerged { classpath ->
70+
if (false == forbiddenApisTest.bundledSignatures.contains('jdk-non-portable')) {
71+
classpath.entries
72+
.findAll { it.kind == "con" && it.toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER") }
73+
.each {
74+
it.accessRules.add(new AccessRule("accessible", "com/sun/net/httpserver/*"))
75+
}
76+
}
77+
}
78+
}
79+
80+
ext.withReleaseBuild = { Closure config ->
81+
if(buildParams.snapshotBuild == false) {
82+
config.call()
83+
}
84+
}
85+
86+
ext.splitForCI = { proj, partString ->
87+
proj.tasks.register("check$partString") {
88+
dependsOn 'check'
89+
withReleaseBuild {
90+
dependsOn 'assemble'
91+
}
92+
}
93+
}
94+
95+
96+
97+
plugins.withId('lifecycle-base') {
98+
if (project.path.startsWith(":x-pack:")) {
99+
if (project.path.contains("security") || project.path.contains(":ml")) {
100+
splitForCI(project, "Part4")
101+
} else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) {
102+
splitForCI(project, "Part3")
103+
} else if (project.path.contains("multi-node")) {
104+
splitForCI(project, "Part5")
105+
} else {
106+
splitForCI(project, "Part2")
107+
}
108+
} else if(project.path.startsWith(":qa:")) {
109+
splitForCI(project, "Part6")
110+
} else {
111+
splitForCI(project, "Part1")
112+
}
113+
tasks.register('functionalTests') {
114+
dependsOn 'check'
115+
withReleaseBuild {
116+
dependsOn 'assemble'
117+
}
118+
}
119+
}
120+
121+
proj.tasks.addRule("Pattern: v<BWC_VERSION>#bwcTest$partString") { name ->
122+
if(name.endsWith("#bwcTest$partString")) {
123+
proj.project.getTasks().register(name) {
124+
task -> task.dependsOn(proj.tasks.named { tskName -> tskName == (name - partString) })
125+
}
126+
}
127+
}
128+
129+
proj.tasks.register("bcUpgradeTest$partString") {
130+
dependsOn tasks.matching { it.name == 'bcUpgradeTest' }
131+
withReleaseBuild {
132+
dependsOn 'assemble'
133+
}
134+
}
135+
136+
plugins.withId('lifecycle-base') {
137+
if (project.path.startsWith(":x-pack:")) {
138+
if (project.path.contains("security") || project.path.contains(":ml")) {
139+
tasks.register('checkPart4') {
140+
dependsOn 'check'
141+
withReleaseBuild {
142+
dependsOn 'assemble'
143+
}
144+
}
145+
} else if (project.path == ":x-pack:plugin" || project.path.contains("ql") || project.path.contains("smoke-test")) {
146+
tasks.register('checkPart3') {
147+
dependsOn 'check'
148+
withReleaseBuild {
149+
dependsOn 'assemble'
150+
}
151+
}
152+
} else if (project.path.contains("multi-node")) {
153+
tasks.register('checkPart5') {
154+
dependsOn 'check'
155+
withReleaseBuild {
156+
dependsOn 'assemble'
157+
}
158+
}
159+
} else {
160+
tasks.register('checkPart2') {
161+
dependsOn 'check'
162+
withReleaseBuild {
163+
dependsOn 'assemble'
164+
}
165+
}
166+
}
167+
} else {
168+
tasks.register('checkPart1') {
169+
dependsOn 'check'
170+
withReleaseBuild {
171+
dependsOn 'assemble'
172+
}
173+
}
174+
}
175+
tasks.register('functionalTests') {
176+
dependsOn 'check'
177+
withReleaseBuild {
178+
dependsOn 'assemble'
179+
}
180+
}
181+
}
182+
183+
/*
184+
* Remove assemble/dependenciesInfo on all qa projects because we don't
185+
* need to publish artifacts for them.
186+
*/
187+
if (project.name.equals('qa') || project.path.contains(':qa:')) {
188+
maybeConfigure(project.tasks, 'assemble') {
189+
it.enabled = false
190+
}
191+
maybeConfigure(project.tasks, 'dependenciesInfo') {
192+
it.enabled = false
193+
}
194+
}

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
}

0 commit comments

Comments
 (0)