-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for concatenated plugin caches #2887
Conversation
`Log4j2Plugins.dat` descriptors cause problems while shading an application that uses Log4j Core, since they need a specialized resource transformer to be merged. We maintain such a resource transformer for the Maven Shade Plugin and Gradle Up Shadow also contains a similar tool. Both of them have open issues. The remaining shading build tools, such as SBT Assembly, however, don't have any resource transformer capable of dealing with the `Log4j2Plugins.dat` format. This PR extends the `Log4j2Plugins.dat` format to allow it to contain `\n`-separated lists of serialized `PluginCache` objects. This will allow users to merge plugin caches using more standard tools.
Together with this PR, we will have 3 plugin descriptor formats:
Can we instead backport I understand the temptation for this easy fix and I am aware that backporting
Last minute edit: Though backporting |
There is no pressing need for this PR, I only created it as a response to this I find shading a bad practice too:
|
While I like the I agree with Volkan here that having three formats is not ideal, and even two formats is annoying enough (I had hoped to eliminate support for the .dat format in 3.0, but that's the only thing that allows for 2.x plugins to still be loadable due to annotation changes). Could we have some sort of compromise where the .dat parser can work in a lax mode or something where it tries to continue parsing a concatenated .dat file? |
That is exactly what this PR does: the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a reasonable approach even though it reminds me of how we bundled everything in Core due to developers' ignorance of dependency management.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though I find it helpful, I am not in favor of this hack relaxed-mode for following reasons:
- PR is developed in response to a user trying to implement a JTL pretty-printer in a shaded application built using SBT. This is wrong in two major ways:
- She is doing wrong by trying to pretty-print JTL (already explained this to her)
- She is doing wrong by using shading
- PR further complicates the officially accepted Log4j plugin descriptor file format
- We haven't received a single legitimate complaint from SBT users. I don't see a pressing need. This is important and a sensitive point, in particular, given Log4j is known for its bloat. We already massively revamped the docs. Let's first collect some user feedback before settling down on a solution.
These said, PR is technically sound. If there is a consensus from other maintainers to get this in, I won't stop in the way.
== Merging plugin descriptors | ||
|
||
The plugin descriptor is located in a JAR file at the following fixed location: | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
---- | |
[source] | |
---- |
You can use the | ||
https://github.com/GradleUp/shadow/blob/main/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy[`Log4j2PluginsCacheFileTransformer`]. | ||
|
||
* Since version `2.24.0` you can any resource transformer capable of concatenating files using `\n` as separator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Since version `2.24.0` you can any resource transformer capable of concatenating files using `\n` as separator. | |
* Since version `2.24.0`, you can employ any resource transformer capable of concatenating files using `\n` as separator. |
|
||
assertThat(actual) | ||
.as("Deserialized plugin cache") | ||
.isEqualTo(createSampleCache().getAllCategories()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd prefer createSampleCache()
accept categories and entries, instead of assuming hardcoded values will be identical in multiple places.
I agree with Volkan still. No strong feelings from me on whether we should support this. |
Although I am the author of the PR, I also agree with Volkan. So we have consensus! |
Log4j2Plugins.dat
descriptors cause problems while shading an application that uses Log4j Core, since they need a specialized resource transformer to be merged.We maintain such a resource transformer for the Maven Shade Plugin and Gradle Up Shadow also contains a similar tool. Both of them have open issues.
The remaining shading build tools, such as SBT Assembly, however, don't have any resource transformer capable of dealing with the
Log4j2Plugins.dat
format.This PR extends the
Log4j2Plugins.dat
format to allow it to contain\n
-separated lists of serializedPluginCache
objects.This will allow users to merge plugin caches using more standard tools.