-
Notifications
You must be signed in to change notification settings - Fork 92
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
New formatter config must invalidate cache #453
Comments
Why not just do |
If this behaviour could be clearly documented, I think that would be an OK solution. As it was, I spent half an hour in redis/jedis#2495 trying to figure out why the formatter did one thing locally and another thing in CI. Any change in this plugin that could have saved me (and future users who run into the same thing) that half hour would be much appreciated. Maybe just checksum the formatter config as well and drop the other cache if it changes? Or just skip the caching entirely; how much time does from-scratch reformatting really take? Caching is hard :) |
How much time does it save, a lot. We didn't have a cache a year ago. Much larger projects were looking for support there and it saved quite a bit. Actually as a result, caching is being asked on other related plugins now just for that reason. The default cache is in the target directory, so if you run 'clean', its deleted. Generally anytime configuration is changed, 'clean' should be run otherwise it uses stale cache. Great example, changing a pom file dependency. Without clean you will end up with duplicate libs. |
That is to say saved cache....it was there but never worked correctly prior to last year. |
I'm open to suggestions, but I'm not sure what other documentation is needed to help users understand how to delete the cache that has been invalidated by a change to their Maven project. This might just be a thing that one needs to be pointed to if they didn't already make the connection themselves. |
How to delete the cache is obvious and doesn't need any (more) documentation. What's not obvious is that the cache has to be deleted manually in the first place. And if that could also be clearly documented (or fixed in the code), that would be super! |
I suppose a naive attempt to solve this could be by having a special cache entry for the loaded config file... but so many other things matter... like the java compliance version, and the version of this plugin, and the version of any manually overridden Eclipse dependencies in the While it seems like a nice idea to have such a feature to automatically detect when the cache is invalid, I just don't think it's feasible for for the plugin to try to attempt it... there are too many variables. I think, just because of practical reasons, it has to be left up to the users to be able to figure out when, if at all, the cache is going to be valid, based on the changes to the project that they know they made, rather than the plugin trying to detect and deduce what changes they made. I'm not even sure what we could document to hint to the user that a cache might no longer be valid. If I were to make an attempt to document something, it would be something very generic, like "The cache can become invalid for any number of reasons that this plugin can't reasonably detect automatically. If you rely on the cache and make any changes to the project that could conceivably make the cache invalid, or if you notice that files aren't being reformatted when they should, just delete the cache and it will be rebuilt." I'm not sure how useful that would be, though. I'm open to suggestions. |
That would have saved me. I would like this! |
This seems like a waste of time to me. I don't think we can, or should try to, automate away the the user's responsibility to understand the impact of their environmental changes on their build. It seems likely to increase complexity of this plugin, but not actually help users much. The user, not the plugin, is in the best position to understand the consequences of the changes they make to the build environment. As I said, any number of environmental changes could cause the same issue, and it would be unreasonable for the plugin to try to detect them all. Just trying to detect all these changes could easily become a substantial percentage of this plugin's code, and I don't know why this specific one is any more special than any of the others... it's just the one you saw. It's not necessarily the one that the next user will see, or the next. So, I won't spend time trying to chase these kinds of user experiences down one-by-one, but if somebody else wants to put together a pull request to address it, even though I'm not enthusiastic about it, I won't object, as long as it doesn't bloat the code too much. |
In that case I think the exact wording you suggested should go into the plugin documentation, that would be the next best thing:
|
* Bump formatter to latest release for current build * Update the javadoc for the cache to warn about changes a user might make that would invalidate any cache (re #453)
* Bump formatter to latest release for current build * Update the javadoc for the cache to warn about changes a user might make that would invalidate any cache (re #453)
Coming from revelc/impsort-maven-plugin#48.
IMHO, this is too black and white. What plugins, frameworks etc. should do is to help users as good as they can.
This might be true for the user altering the config or updating the plugin. But once you pushed your change and it lands in the local workspaces of dozens of contributors/team members, it's mostly out of your hand. And at this point I have to ask: What happens more often? A cache-relevant config change or a Btw, Checkstyle is considering the config for calculating the hashes: https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java PS: Having said that, it's good that there now is an explicit hint in the plugin doc that you might (will) have to wipe the cache on your own. When I moved the cache out of target in Quarkus in March this year, there wasn't such a hint yet. |
The problem is knowing which changes are cache-relevant. Some config changes might be, while others aren't. A version bump is unlikely to change the formatting in most cases. I think it's reasonable to defer to users to manage the lifecycle of their cache when they make changes to their build. As I see it, there's basically two competing groups here:
As somebody who always does For me, the safest thing to do seems to just stay out of it and leave it up to the user to be responsible for the cache lifecycle. If they want to leave it in the default location, then it's just a matter of rebuilding with |
Even the speed focussed folks should be able to agree to "correctness over speed". A reliable build process should never sacrifice correctness to speed. TBH, I also don't see that there are really two strictly opposing groups. The primary reason to use this plugin is auto-formatting and/or validation (often both, auto-formatting locally and validation in CI).
Btw, typically only a very small fraction of the users of a project has in-depth knowledge of build process. Most folks just want to have their stuff compiled, tested and packaged. |
Of course. The problem is that not every version bump or configuration change will result in any change to correctness, and many of them are just a waste. It's hard for this plugin to be able to determine which is the case. It's also possible that there is a correctness issue due to something else in the environment that has changed that this plugin has no way of detecting. I just don't see a lot of value for this plugin trying to maintain all those heuristics, when the user is in a much better position to know when they should clear their cache and when not do... much more so than the developers of this plugin.
The only person who needs to know to do this would be the person who makes a cache-relevant change in the first place. If they check in their changes to their SCM, then everybody else will see those changes, and their local caches will automatically be invalidated because the file has changed. If a user doesn't know the consequences of making a config change or bumping the plugin version, then they shouldn't do it! if they do know the consequences, then it's easy for them to clear the cache as appropriate. |
In any case, all of this is philosophical. If somebody wants to do the work, then they can submit a PR to do it. If it's not so substantial that it creates a maintenance burden, then I wouldn't object to it. If nobody that thinks it is important wants to do the work, then the whole conversation is moot. |
Fair enough! I'll see if I can find some time to take a stab at this. Btw, there could also be a property like |
@walles @famod I didn't reread this as it is long but thinking on the subject. It seems like if we just write the configuration used into the caching files it would then be simple enough to check if it was changed and invalidate that way without having to do much more. If someone can produce a PR along these lines that would help. |
In fact, at some point I'm actually going to remove this cache entirely from this project and make it its own plugin. There are too many other plugins that would benefit from it that are incredibly slow and it doesn't make sense to re-invent the wheel but for now, I too now would like to see this for cache eviction so its basically feature complete when I make a break for it :) Context: I need the caching for license-maven-plugin as it is incredibly slow compared to all others currently but I know a lot in this are that look at physical files would benefit by skipping reads when not needed. |
If I instruct the plugin to achieve a goal: format, and it doesn't get round to any formatting On the other hand, if files did change, lets say 10 requiring formatting and 5 that don't, then it can stay at INFO level. |
The more I think about this the more irritated I get. If caching is such an old feature then why is there no parameter to invalidate the cache, at the very least? And 2 years into this ticket? Reliability > speed. |
As with most plugins the output is critical to know it did something. Nearly all maven direct plugins are now all writing some info so that part won't change here. It's not a warning.
As far as invalidate cache. By default its in target folder. As such run clean lifecycle as most users due such as mvn clean install and the cache is deleted entirely.
Pull requests for any feature are always welcome to review. What I can say is sure lots of old tickets that are not critical to us to address. Personally I manage the builds for roughly 2k repos at my day job along with an extensive super pom and still some of the tickets here I even raised while important to me are not a significant priority. As such that is why tickets hang around in general in OSS. Its likely wanted just no one felt inclined to do much about it.
It could be worse, we could just close all old tickets with a stale bot. Its age doesn't quite matter.
Feel free to contribute if important enough for you. I'm sure others would appreciate it.
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Delany ***@***.***>
Sent: Thursday, April 20, 2023 6:16:00 PM
To: revelc/formatter-maven-plugin ***@***.***>
Cc: Jeremy Landis ***@***.***>; Comment ***@***.***>
Subject: Re: [revelc/formatter-maven-plugin] New formatter config must invalidate cache (#453)
The more I think about this the more irritated I get. If caching is such an old feature then why is there no parameter<https://code.revelc.net/formatter-maven-plugin/format-mojo.html> to invalidate the cache, at the very least? And 2 years into this ticket? Reliability > speed.
—
Reply to this email directly, view it on GitHub<#453 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHODI6U23UES3ZMVH3DHZ3XCGYSBANCNFSM42JM2AAQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
I would argue that this capability already exists. If you choose to keep the cache in the target directory, you can clear it with a For your last comment, about |
Unsure here, but would this really affect the formatting? If not, there's no need to invalidate the formatting cache.
Wouldn't this bump the file timestamps so things get reformatted every time they do this anyway? |
That was a typo. It should have said Eclipse JDT. In any case, yes, it would. The formatting differs in each Eclipse JDT release.
File timestamps can be preserved. You can move across environments by merely mounting an external hard drive or network storage device or by dual-booting. You don't need to change timestamps to change that environment. In any case, for the basic situation that was initially described, a change was already implemented for this in #734, so this issue should have been closed already. There is a follow up issue at #757 that may also be relevant. |
Describe the bug
A clear and concise description of what the bug is.
Versions (OS, Maven, Java, and others, as appropriate):
To Reproduce
git clone [email protected]:walles/jedis.git
cd jedis
git checkout walles/format-on-mvn-validate-in-ci-2019
mvn compile
(this will run the formatter and initialize the cache)hbase-formatter.xml
mvn compile
rm target/formatter-maven-cache.properties
mvn compile
Expected behavior
Files should be reformatted when the formatting rules change.
Actual behavior
Nothing gets reformatted, even if the formatting rules change.
The text was updated successfully, but these errors were encountered: