grails-spring-security-core
grails-spring-security-core copied to clipboard
Classloader clash with other plugins using newer (3.x+) version of Ehcache
The latest (4.0.0) version of this plugin has a dependency on net.sf.ehcache:ehcache:2.9.0. The Ehcache specific classes contained in that dependency are of course contained in the net.sf.ehcache package. That version also contains com.terracotta and org.terracotta packages w/ relevant classes.
Some other more recently updated Grails plugins (I'm looking specifically at org.grails.plugins:cache-ehcache:3.0.0 here) use a newer version of Ehcache (org.ehcache:ehcache:3.4.0). In that version, the Ehcache specific classes use a different package naming convention of org.ehcache, however the org.terracotta classes still exist but with subtly different implementations.
Therefore, when trying to use the latest version of both grails plugins, the following class loader error occurs at startup:
2020-07-12 12:09:33.673 ERROR --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.ehcache.impl.internal.store.basic.BaseStore.registerStatistic(BaseStore.java:82)
The following method did not exist:
'void org.terracotta.statistics.StatisticsManager.createPassThroughStatistic(java.lang.Object, java.lang.String, java.util.Set, org.terracotta.statistics.StatisticType, java.util.function.Supplier)'
The method's class, org.terracotta.statistics.StatisticsManager, is available from the following locations:
jar:file:/Users/jamesdh/.gradle/caches/modules-2/files-2.1/net.sf.ehcache/ehcache/2.10.6/38076997b10f5c762a210ea8b9f6099da35ac5f/ehcache-2.10.6.jar!/org/terracotta/statistics/StatisticsManager.class
jar:file:/Users/jamesdh/.gradle/caches/modules-2/files-2.1/org.ehcache/ehcache/3.6.3/d8da79858f4016e8f3092453cd6b1a4ece6f6d27/ehcache-3.6.3.jar!/org/terracotta/statistics/StatisticsManager.class
It was loaded from the following location:
file:/Users/jamesdh/.gradle/caches/modules-2/files-2.1/net.sf.ehcache/ehcache/2.10.6/38076997b10f5c762a210ea8b9f6099da35ac5f/ehcache-2.10.6.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.terracotta.statistics.StatisticsManager
2020-07-12 12:09:33.692 WARN --- [ restartedMain] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'tomcatMetricsBinder': java.lang.NullPointerException
Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
Steps to Reproduce
- Add
compile "org.grails.plugins:cache-ehcache:3.0.0"as a dependency - Add
compile "org.grails.plugins:spring-security-core:4.0.0"as a dependency
Expected Behaviour
The application will start normally
Actual Behaviour
The application fails to start due to a classloader collision w/ the same classname existing in multiple different dependencies, each with slightly different implementation.
Environment Information
- Operating System: MacOS 10.15.4
- GORM Version: 7.0.4.RELEASE
- Grails Version (if using Grails): 4.0.3
- JDK Version: 11.0.4
Example Application
- https://github.com/jamesdh/grails-ehcache-class-collision
Filed this here because it feels like the most likely place that we can do something about this. I guess ideally Ehcache would have published a 3.x+ version with different classpaths for the org.terracotta classes as well, but that is beyond our control.
I'm guessing that the easiest solution to this is to just upgrade Grails Spring Security Core to use the latest Ehcache version.
Yes, we should update the Grails Spring Security Core plugin to the latest Ehcache version. Would you be interested to send a PR for the same?
@puneetbehl it appears the plugin defines certain spring beans based on Spring Security Core classes which in turn have a hard dependency on the old net.sf.ehcache package e.g. EhCacheBasedUserCache.java.
So it's not just a matter of upgrading the dependency in the build.gradle but appears it may be quite a bit more involved than what I'd feel comfortable taking a jab at given the widespread use of this plugin.
I am running into the same issue. It seems like this is going to be a common issue for folks upgrading to grails 4. Did you find a workaround?
@reecega my fix was I stopped using Grails, unfortunately.