maven-enforcer icon indicating copy to clipboard operation
maven-enforcer copied to clipboard

Rule speedup through dependency resolution caching

Open Stephan202 opened this issue 3 months ago • 0 comments

New feature, improvement proposal

We have a large multi-module build with quite a number of built-in and extra enforcer rules enabled. For modules with many dependencies, plugin execution takes several seconds, adding up to hundreds of seconds over-all. Based on some profiling, most time is spent repeatedly collecting dependency information:

Image

I had a brief look at the code, and besides full rule caching it appears that dependency resolution isn't cached. Would it be possible to add this, such that distinct rules applied to the same module can reuse invariant dependency information?


I suppose that the changes in #930 could be extended to support more fine-grained caching (AbstractResolveDependencies#collectProjectDependencies() would be an easy candidate), but SessionData's documentation explicitly states:

Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion.

There's also EnforcerRuleHelper#getCache(String key, Supplier<?> producer), but EnforcerRuleHelper is deprecated.

I can't promise to have time in the near feature to help implement any improvement in this area, but if one were to attempt this, what would be the recommended approach?

Stephan202 avatar Sep 27 '25 15:09 Stephan202