Remove guava from transitive compile classpath#54309
Remove guava from transitive compile classpath#54309rjernst merged 16 commits intoelastic:masterfrom
Conversation
Guava was removed from Elasticsearch many years ago, but remnants of it remain due to transitive dependencies. When a dependency pulls guava into the compile classpath, devs can inadvertently begin using methods from guava without realizing it. This commit moves guava to a runtime dependency in the modules that it is needed. Note that one special case is the html sanitizer in watcher. The third party dep uses guava in the PolicyFactory class signature. However, only calling a method on the PolicyFactory actually causes the class to be loaded, a reference alone does not trigger compilation to look at the class implementation. There we utilize a MethodHandle for invoking the relevant method at runtime, where guava will continue to exist.
|
Pinging @elastic/es-core-infra (:Core/Infra/Core) |
And people thought Gradle was being dumb by introducing |
mark-vieira
left a comment
There was a problem hiding this comment.
Couple comments, otherwise LGTM.
| configuration.resolutionStrategy.eachDependency { | ||
| String artifactName = it.target.name | ||
| if (FORBIDDEN_DEPENDENCIES.contains(artifactName)) { | ||
| throw new GradleException("Dependency '${artifactName}' on configuration '${configuration.name}' is not allowed. " + |
There was a problem hiding this comment.
We might want to include the full path to the configuration here as just saying "compileClasspath" isn't going to be particularly helpful.
There was a problem hiding this comment.
This is the current failure output. It has the full path in the first part of the error.
> Could not resolve all files for configuration ':x-pack:plugin:identity-provider:compileClasspath'.
> Could not resolve com.google.guava:guava:19.0.
Required by:
project :x-pack:plugin:identity-provider
> Dependency 'guava' on configuration 'compileClasspath' is not allowed. If it is needed as a transitive depenency, try adding it to the runtime classpath
| } | ||
|
|
||
| subprojects { | ||
| pluginManager.withPlugin('java') { |
There was a problem hiding this comment.
It's worth nothing that standalone QA projects do no apply the java plugin but only java-base.
There was a problem hiding this comment.
I appreciate that, but still think this is a good start.
|
This pull request is a thing of beauty to bury the zombie that tried to come back. |
Guava was removed from Elasticsearch many years ago, but remnants of it remain due to transitive dependencies. When a dependency pulls guava into the compile classpath, devs can inadvertently begin using methods from guava without realizing it. This commit moves guava to a runtime dependency in the modules that it is needed. Note that one special case is the html sanitizer in watcher. The third party dep uses guava in the PolicyFactory class signature. However, only calling a method on the PolicyFactory actually causes the class to be loaded, a reference alone does not trigger compilation to look at the class implementation. There we utilize a MethodHandle for invoking the relevant method at runtime, where guava will continue to exist.
Guava was removed from Elasticsearch many years ago, but remnants of it remain due to transitive dependencies. When a dependency pulls guava into the compile classpath, devs can inadvertently begin using methods from guava without realizing it. This commit moves guava to a runtime dependency in the modules that it is needed. Note that one special case is the html sanitizer in watcher. The third party dep uses guava in the PolicyFactory class signature. However, only calling a method on the PolicyFactory actually causes the class to be loaded, a reference alone does not trigger compilation to look at the class implementation. There we utilize a MethodHandle for invoking the relevant method at runtime, where guava will continue to exist.
Guava was removed from Elasticsearch many years ago, but remnants of it
remain due to transitive dependencies. When a dependency pulls guava
into the compile classpath, devs can inadvertently begin using methods
from guava without realizing it. This commit moves guava to a runtime
dependency in the modules that it is needed.
Note that one special case is the html sanitizer in watcher. The third
party dep uses guava in the PolicyFactory class signature. However, only
calling a method on the PolicyFactory actually causes the class to be
loaded, a reference alone does not trigger compilation to look at the
class implementation. There we utilize a MethodHandle for invoking the
relevant method at runtime, where guava will continue to exist.
Additionally, this commit adds a build time check that we do not add any compile dependency on guava.