Search code examples
javaplayframeworksbtnettylettuce

Using lettuce 4.4 with play framework 2.5.5


I am trying to use lettuce version 4.4 as a Redis client library in a play framework 2.5.5 project. Looks like there are some compatibility issues with the netty versions used by play 2.5.5 and lettuce 4.4.

I am seeing a java.nio.channels.UnresolvedAddressException while redis client is attempting to connect to a locally installed redis server. I've ensured that the redis server is running fine. Also, I am able to connect to redis using lettuce 4.4 from an independent maven based java project.

To troubleshoot the issue, I have reproduced the problem in the independent maven project by specifying netty dependency explicitly as follows:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.0.20.Final</version>
</dependency>

And I am able to resolve the issue in the maven project by using the shaded-jar where dependencies are relocated to com.lambdaworks package to avoid version conflicts, as mentioned in https://github.com/lettuce-io/lettuce-core#binariesdownload. To use the shaded jar, 'classifier' property is added to the lettuce dependency definition with value 'shaded', and also a list of exclusions are specified. How do I achieve the same using build.sbt?

As per http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies, I can specify exclusions in build.sbt, but not sure how to set classifier property. With just the list of exclusions, it does not seem to work.


Solution

  • Finally, I am able to resolve the issue by specifying the shaded classifier and exclusions in the build.sbt as below:

      "biz.paluch.redis" % "lettuce" % "4.4.0.Final" classifier "shaded" excludeAll(
        ExclusionRule(organization = "io.reactivex", artifact="rxjava"),
        ExclusionRule(organization = "org.latencyutils", artifact="LatencyUtils"),
        ExclusionRule(organization = "io.netty", artifact="netty-common"),
        ExclusionRule(organization = "io.netty", artifact="netty-transport"),
        ExclusionRule(organization = "io.netty", artifact="netty-handler"),
        ExclusionRule(organization = "io.netty", artifact="netty-codec"),
        ExclusionRule(organization = "com.google.guava", artifact="guava"),
        ExclusionRule(organization = "io.netty", artifact="netty-transport-native-epoll"),
        ExclusionRule(organization = "io.apache.commons", artifact="commons-pool2"))
    )