Mojo
Mojo

Reputation: 1202

How do i fix these dependency warnings

I keep seeing these messages when I launch sbt shell for my play application:

[warn]  * com.typesafe.akka:akka-actor_2.11:2.5.21 is selected over {2.3.13, 2.4.20}
[warn]      +- com.typesafe.akka:akka-slf4j_2.11:2.5.21 ()        (depends on 2.5.21)
[warn]      +- com.typesafe.play:play_2.11:2.6.23 ()              (depends on 2.5.21)
[warn]      +- com.typesafe.akka:akka-stream_2.11:2.5.21 ()       (depends on 2.5.21)
[warn]      +- com.typesafe.akka:akka-parsing_2.11:10.0.15 ()     (depends on 2.4.20)

How do i fix this? Do I need to explicitly set the akka version so it doesn't pick 2.5.21?

Upvotes: 0

Views: 204

Answers (2)

alberto adami
alberto adami

Reputation: 749

What you're getting is an eviction warning by sbt, you can check the documentation at this link.

What you could do is to override the dependency used on the sbt file, to avoid runtime errors.

For example:

dependencyOverrides += "com.typesafe.akka" %% "akka-actor" % "2.5.21"

In this way you're specifying to sbt which version of the library to use. You can check also the sbt's plugin dependency-graphto understand all the dependencies inside your project.

Upvotes: 1

Denis Makarenko
Denis Makarenko

Reputation: 2938

I'd recommend to hook up the sbt-dependency-graph sbt plugin and use the following commands to figure out which components depend on which version of akka-actor

sbt <project>/dependencyTree
sbt "<project>/whatDependsOn <organization> <module> <revision>"
sbt <project>/evicted

After coming up with the list of component dependencies, you have a few choices:

  • Make sure you use the versions of the components (like play) that require the same version of akka-actor and akka in general. I usually do it by checking POM files for the libraries in question at https://mvnrepository.com/
  • Force sbt to use a particular version of akka (via dependencyOverrides). It is generally safe to do for different patch versions (as in major.minor.patch) for libraries that use semantic versioning (https://semver.org/). But it may cause problems for different minor and especially major versions if they are not backwards compatible.
  • Ignore the conflicts and warnings if they aren't causing problems.
  • If you use sbt-assembly to create Fat jars, you can use shading to allow multiple versions of akka to live in the same application via moving one of them to a different package. It is not always possible though (e.g. when a library loads a class dynamically by name)
  • write a custom class loader to dynamically load different versions of a library into separate protection domains. It is not trivial and requires quite a bit of code. I wouldn't recommend it for akka.

Upvotes: 2

Related Questions