How to get Spring to use older version of Guava for specific Dependency, but newer version for "main" project - spring

I have a dependency in my SpringBoot project:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cluster-zookeeper</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
Which requires Guava 16.01
However, my "main" project which I'm including cluster-zookeeper in requires Guava 28.2
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
When I run SpringBoot App, I get error:
The following method did not exist:
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;
The method's class, com.google.common.util.concurrent.MoreExecutors, is available from the following locations:
jar:file:/blah/.m2/repository/com/google/guava/guava/28.2-jre/guava-28.2-jre.jar!/com/google/common/util/concurrent/MoreExecutors.class
It was loaded from the following location:
file: /blah/.m2/repository/com/google/guava/guava/28.2-jre/guava-28.2-jre.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.util.concurrent.MoreExecutors
It seems like a version conflict issue where Spring tries to get cluster-zookeeper to use newer Guava version, when it require older one. How can I get this to work? I.e use 16.01 Guava for ONLY cluster-zookeeper while keeping 28.2 dependency for my main project?

Related

SnakeYAML version not changing from 1.30 to 1.33 for my springboot project

These are the lines in my pom.xml:
<snakeyaml.version>1.33</snakeyaml.version>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
I added the new version dependency but the project still uses version 1.30. I believe some other things are controllling cthe snakeyaml version
I excluded all conflicting transitive dependencies and still the problem is not solved.
I am using springboot version: 2.7.6 for the project.

Method does not exist: org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)

I am creating Hibernate Search 6 application with Spring Boot 2.3.4
I am facing this error while I try to build my application -
Description:
An attempt was made to call a method that does not exist. The attempt was made from the
following location:
org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientImpl.setPerRequestSocketTimeout(ElasticsearchClientImpl.java:198)
The following method did not exist:
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:
jar:file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar!/org/elasticsearch/client/RequestOptions$Builder.class
The class hierarchy was loaded from the following locations:
org.elasticsearch.client.RequestOptions.Builder:
file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RequestOptions$Builder
Following are the dependencies that i have added -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<version>6.1.5.Final</version>
</dependency>
Let me know if I missing something.
This is all explained here: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#gettingstarted-framework-spring-boot-dependency-versions
Basically, Spring Boot is managing your dependencies, and it's forcing an older version of the Elasticsearch client. You need to force it back to the version Hibernate Search expects (a newer version, 7.16.x).
And just to clarify, this has nothing to do with the Elasticsearch server version that I've seen mentioned in other answers. This is strictly about your client.
This is probably due to incompatible version of the elasticsearch dependency. From https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#getting-started-compatibility it seems you need 7.10 or 7.16 but you have 7.6 dependency. Also check server version to be sure.
hibernate-search-backend-elasticsearch
is internally dependent on elasticsearch-rest-client-7.6.2.jar
And the method
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
it is trying to find is in later versions of low level client.
Temporary solution will be to exclude 7.6.2 and include latest version of elasticsearch-rest-client-7.6.2.jar -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<exclusions>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
</exclusion>
</exclusions>
</dependency>
and including,
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.10.0</version>
</dependency>
Since this is a temporary, I am not sure if this is reliable.
Please let me know in case there is a better solution.

Cannot find openam-oauth2-common 13.0.0 version

We are upgrading openam to version 13. I've set artifacts version to 13.0.0 but when I start building the service with Maven I get a error message saying:
failure to find org.forgerock.openam:openam-oauth2-common:jar:13.0.0.
We are using forgerock repository: http://maven.forgerock.org/repo/repo/
Question: why the dependency is suddendly not available any longer and how to properly upgrade it?
It appears that the artifact you were using has been refactored, moving from a single project (i.e. a library) to a multi-module project (several modules, several libraries). Hence, although its Maven coordinates have not changed (GAV, GroupId, ArtifactId, Version), the usage (the consumption) of this library has been directly affected because its type has changed (again, from jar to pom).
Version 11.0.0, for example, was a jar, hence you could import it as most of the Maven dependency, via a dependency section.
However, since version 12.0.0, the artifact is a pom defining the following modules:
<module>oauth2-core</module>
<module>oauth2-restlet</module>
<module>openid-connect-core</module>
<module>openid-connect-restlet</module>
<module>oauth2-oidc-test-server</module>
Hence, what previously would have been:
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openam-oauth2-common</artifactId>
<scope>provided</scope>
<version>11.0.0</version>
</dependency>
It cannot be simply upgraded via its version number but must be replaced via several dependencies (you can now narrow down what you actually need):
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>oauth2-core</artifactId>
<version>13.0.0</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>oauth2-restlet</artifactId>
<version>13.0.0</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openid-connect-core</artifactId>
<version>13.0.0</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openid-connect-restlet</artifactId>
<version>13.0.0</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>oauth2-oidc-test-server</artifactId>
<version>13.0.0</version>
</dependency>
Most probably version 11.0.0 is provided as a subset of the dependencies above, including them should fix the issue (but you could also investigate later on which one is effectively required by your project, e.g. the last one, oauth2-oidc-test-server, is most probably not required simply looking at its artifactId name, as an immediate guess).

Serialization errors due to jackson-databind version mismatch?

I am running into the following error
java.lang.NoSuchFieldError: WRITE_DURATIONS_AS_TIMESTAMPS
at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.<init>(DurationSerializer.java:28)
at com.fasterxml.jackson.datatype.joda.ser.DurationSerializer.<init>(DurationSerializer.java:25)
at com.fasterxml.jackson.datatype.joda.JodaModule.<init>(JodaModule.java:45)
I checked to see what versions of jackson-datatype-joda are available. It appears that maven has excluded all version mismatches.
Any other reason this might cause serialization errors?
The problem is that among the maven dependencies (mind that it could be a transitive one) you have incompatible versions of jackson-datatype-joda and jackson-databind. Incompatible in the sense that jackson-databind's SerializationFeature class is missing the WRITE_DURATIONS_AS_TIMESTAMPS field. To see what dependencies maven brings you can run the following command in the terminal (or you can use an IDE's maven plug to search and analyse the maven dependency tree):
mvn dependency:tree | grep databind
the outcome will most probably be something like:
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.1:compile
The version of course can vary but the important thing is that the WRITE_DURATIONS_AS_TIMESTAMPS field is only available since version 2.5
You can exclude a transitive dependency like this:
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>${artifact.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
If it's not a transitive dependency you need to update version of jackson-databind.
I got it resolved by using following dependency as this dependency has overridden any other version used:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.5.3</version>
</dependency>
I had same error. I had included all jackson*2.7.0 libraries under WEB-INF/lib/ and i was still getting that error. I am using wildfly 8.2 and it had jackson 2.4.1 libraries under modules and somehow it was loading 2.4.1 jars from that location. So I had to manually upgrade them to 2.7.0 which fixed the issue. I was under impression that if I did not mention it to load jackson jars in deployment configuration file, it would not load wildfly jars. I guess I was wrong.

Drools 6 sisu-guava conflicts with guava

We have recently upgraded from Drools 5 to Drools 6 and have run into disturbing conflict issues.
We have kie-ci imported into out project. kie-ci brings in sisu-guava. sisu-guava changes the accessibility of some of the classes from google's guava. Unfortunately, it uses the same package name as google's guava.
Since we're working with google's guava in our project, we are running into conflicts of classes.
An attempt to remove sisu-guava from the project (using a maven exclusion) results in accessibility exceptions, as the kie-ci code attempt to access classes which are public in sisu-guava but are private in google's guava.
Any idea how to get round this.
This may not be correct solution for all situation, but I was able to resolve this issue by excluding the susi-guava jar in my pom:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-kie-services</artifactId>
<version>${jbpm.version}</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guava</artifactId>
</exclusion>
</exclusions>
</dependency>
I seem to have the same problem using drools 6.2. Drools is dependent on guava 10.0.1, where as my project had a dependency on guava 16 and maven was picking the version 16 (correctly).
On inspecting the dependency tree, I find that the drools dependency on guava is dictated by "org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M5:runtime".
There is a newer version of org.eclipse.sisu.plexus, so I added the following to my project's pom to pick up the latest version, which is:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.3.1</version>
</dependency>
</dependencies>
</dependencyManagement>
Now, there does not seem to be a dependency on guava, for drools and the problem is solved and my project can use version 16 of guava.

Resources