Skip to content

Commit e7e97f6

Browse files
committed
Fix rest client causing jarHell for gradle 3.5+ (#25892)
The configuration removed from the runtime configuration did not properly remove the deps jar from gradle versions > 3.3. The rest client now removes both the 3.3 and 3.3+ configurations so this works on both versions of gradle. Closes #25884 Relates #25208
1 parent 5a5e931 commit e7e97f6

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

client/rest/build.gradle

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,18 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
2121

2222
/**
2323
* The rest client is a shaded jar. It contains the source of the rest client, as well as all the dependencies,
24-
* shaded to the `org.elasticsearch.client` package. 3 artifacts come out of this build process. The shading process only
25-
* modifies the imports and class names and locations. It does not do any processing on the files. The classes used to
26-
* interact with the rest client are no different from the dependencies in the shade configuration, besides in name.
24+
* shaded to the `org.elasticsearch.client` package. 2 artifacts come out of this build process. The shading process
25+
* only modifies the imports and class names and locations. It does not do any processing on the files. The classes used
26+
* to interact with the rest client are no different from the dependencies in the shade configuration, besides in name.
2727
*
2828
* IDEs do not like removing artifacts and changing configurations on the fly, so the bits that make the build use the
29-
* actual shaded jar (3) are only executed on the cli. Tests run in an IDE rely on the deps (1) and nodeps (2) jars.
29+
* actual shaded jar (2) are only executed on the cli. Tests run in an IDE rely on the deps (1) jar.
3030
*
31-
* 1) A jar that contains *only* the `org.elasticsearch.client` dependencies. This is a jar that is built before the src
32-
* is compiled. This jar is only used by the rest client so its compilable. There exists a chicken-egg situation where
33-
* the src needs compilation and depends on `org.elasticsearch.client` classes, so an intermediary jar needs to exist
34-
* to satisfy the compile. The `deps` classifier is added to this jar.
35-
* 2) The original src/ contents, using the `org.elasticsearch.client` packages, but without the `org.elasticsearch.client`
36-
* code also in the jar. The reason this jar was not overwritten was because gradle knows what its inputs and outputs
37-
* are for a given task and we should not alter that by overwriting the original jar. What we do is add a `nodeps`
38-
* classifier to it instead.
39-
* 3) The *actual* jar that will be used by clients. This has no classifier, contains the rest client src and
31+
* 1) A jar that contains *only* the `org.elasticsearch.client` shaded dependencies. This is a jar that is built before
32+
* the src is compiled. This jar is only used by the rest client so will compile. There exists a chicken-egg
33+
* situation where the src needs compilation and depends on `org.elasticsearch.client` shaded classes, so an
34+
* intermediary jar needs to exist to satisfy the compile. The `deps` classifier is added to this jar.
35+
* 2) The *actual* jar that will be used by clients. This has no classifier, contains the rest client src and
4036
* `org.elasticsearch.client`. This jar is the only actual output artifact of this job.
4137
*/
4238
plugins {
@@ -84,28 +80,18 @@ task shadeDeps(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)
8480
}
8581
}
8682

87-
// builds the actual shaded jar that is being distributed
88-
shadowJar {
89-
configurations = [project.configurations.shade]
90-
classifier = null
91-
relocate 'org.apache', 'org.elasticsearch.client'
92-
}
93-
9483
jar {
95-
// move the default jar to another classifier so the jar with the shaded dependencies can have the empty classifier
96-
classifier = 'nodeps'
84+
from zipTree(shadeDeps.outputs.files.singleFile)
85+
dependsOn shadeDeps
9786
}
9887

99-
// Mangle this build so it outputs the correct artifacts
100-
// readds the shadowJar output (the actual uber jar) but only from the cli
88+
// remove the deps jar from the classpath to avoid jarHell
10189
if (isIdea == false && isEclipse == false) {
102-
// removes the -nodeps jar
103-
configurations.runtime.artifacts.removeAll { it.archiveTask.is jar }
104-
105-
// removes the runtime configuration inheritance from compile
106-
configurations.runtime.extendsFrom -= [configurations.compile]
107-
artifacts {
108-
runtime project.tasks.shadowJar
90+
// cleanup to remove the deps jar from the classpath
91+
if (gradle.gradleVersion == "3.3") {
92+
configurations.runtime.extendsFrom -= [configurations.compile]
93+
} else if (gradle.gradleVersion > "3.3") {
94+
configurations.runtimeElements.extendsFrom = []
10995
}
11096
}
11197

core/src/main/resources/org/elasticsearch/bootstrap/test-framework.policy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ grant codeBase "${codebase.elasticsearch-rest-client-5.6.0-SNAPSHOT.jar}" {
6363
permission java.net.NetPermission "getProxySelector";
6464
};
6565

66+
// IDEs need this because they do not play nicely with removing artifacts on projects,
67+
// so we keep it in here for IDE test support
68+
grant codeBase "${codebase.elasticsearch-rest-client-5.6.0-SNAPSHOT-deps.jar}" {
69+
// rest makes socket connections for rest tests
70+
permission java.net.SocketPermission "*", "connect";
71+
};
72+
6673
grant codeBase "${codebase.httpasyncclient-4.1.2.jar}" {
6774
// rest client uses system properties which gets the default proxy
6875
permission java.net.NetPermission "getProxySelector";

0 commit comments

Comments
 (0)