mockserver
mockserver copied to clipboard
Using mockserver-client-java-no-dependencies causes package collision with com.google.common.cache
Describe the issue
When using Guava cache , and after replacing the mockserver-client-java dependency with mockserver-client-java-no-dependencies dependency we get the following error:
com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchFieldError: ASCII
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2053) ~[mockserver-client-java-no-dependencies-5.13.2.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:3966) ~[mockserver-client-java-no-dependencies-5.13.2.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3989) ~[mockserver-client-java-no-dependencies-5.13.2.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4950) ~[mockserver-client-java-no-dependencies-5.13.2.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4956) ~[mockserver-client-java-no-dependencies-5.13.2.jar:na]
Workaround
I built mockserver-client-java-no-dependencies:5.13.2 locally, with a minimal change to shading:
<relocation>
<pattern>com.google</pattern>
<shadedPattern>shaded_package.com.google</shadedPattern>
</relocation>
This seems to resolve the issue (The right jar is being used for the Guava package). I wonder why com.google is intentionally not relocated ?
What you are trying to do
I am implementing an integration test that involves a few test containers , including a mockserver test container and a mockserver client to configure it. We are using the mockserver-client-java dependency but it causes us a few problems with transitive dependencies so mockserver-client-java-no-dependencies seems like a natural solution to the problem and we would like to use it instead if possible.
MockServer version 5.13.2
To Reproduce
- Have a project with the following dependencies:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java-no-dependencies</artifactId>
<version>5.13.2</version>
<scope>test</scope>
</dependency>
- Create a Guava LoadingCache and use it.
Sadly I can't remember why I thought com.google caused an issue before, but it was excluded for a reason. Perhaps it would be safer to only shade com.google.guava
Thanks for the response @jamesdbloom !
I'm not sure shading com.google.guava would do the trick. The issue surfaces from com.google.common as you can see in the above stack trace snippet.
That being said - I can try running a more targeted/specific shading for various packages under com.google until I get the desired results (though it won't guarantee that it'll work for all the library users and all use cases)
PR is now merged so this should be fixed a new release will be made in the next week or so
Thanks @jamesdbloom ! 🙏 Much appreciated