Skip to content

Commit

Permalink
Don't pass on akka-http as an explicit-runtime dep
Browse files Browse the repository at this point in the history
The Play framework is very particular about the versions of Akka and
Akka HTTP that it uses:

https://www.playframework.com/documentation/2.8.x/ScalaAkka#Updating-Akka-version

Unless you're directly using Akka HTTP, it's best to avoid explicitly
adding Akka HTTP as a dependency (even a transitive one) on a Play
project, because it's quite likely you'll choose a different version to
Play, and mixed versions are not allowed:

https://doc.akka.io/docs/akka/2.6/common/binary-compatibility-rules.html#mixed-versioning-is-not-allowed

In the case of #79,
which added `akka-http` as a runtime dependency of `play-googleauth`,
the dependency caused `ClassNotFoundException`s at runtime in the Ophan
project when we upgraded to the latest version of `play-googleauth`:

```
[error] Caused by: java.lang.ClassNotFoundException: akka.http.javadsl.UseHttp2
[error] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] 	at play.core.server.AkkaHttpServerProvider.createServer(AkkaHttpServer.scala:647)
[error] 	at play.core.server.AkkaHttpServerProvider.createServer(AkkaHttpServer.scala:645)
[error] 	at play.core.server.DevServerStart$.$anonfun$mainDev$1(DevServerStart.scala:268)
```

Note that PR #79 mentions that the `akka-http` dependency is only needed
to make the tests compile:

25a86c6

...this gives us an easy fix - only add `akka-http` as a dependency for
the *tests*, _not_ the main code - ie make it a test-scoped dependency,
by adding `% Test` on the end:

https://www.scala-sbt.org/1.x/docs/Library-Dependencies.html#Per-configuration+dependencies

Now projects _using_ `play-googleauth` won't have any version of `akka-http`
transitively included for them, but the tests will still compile.

I've also lowered the version of `akka-http` used within the tests to
make it a little more realistic, to a version that's apparently what
real versions of Play actually are using:

https://github.com/playframework/playframework/blob/2.8.5/project/Dependencies.scala#L11
https://github.com/playframework/playframework/blob/2.7.7/project/Dependencies.scala#L11

...but that's just a nod to realism in the tests, it doesn't have to
be completely accurate there!
  • Loading branch information
rtyley committed Nov 27, 2020
1 parent 0a5bcb2 commit 04cefaa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def projectWithPlayVersion(majorMinorVersion: String) =
libraryDependencies ++= Seq(
"com.gu.play-secret-rotation" %% "core" % "0.17",
"org.typelevel" %% "cats-core" % "2.0.0",
"com.typesafe.akka" %% "akka-http-core" % "10.2.0",
commonsCodec,
"org.scalatest" %% "scalatest" % "3.0.8" % "test"
"org.scalatest" %% "scalatest" % "3.0.8" % Test,
"com.typesafe.akka" %% "akka-http-core" % "10.1.12" % Test
) ++ googleDirectoryAPI ++ playLibs(majorMinorVersion),

sonatypeReleaseSettings
Expand Down

0 comments on commit 04cefaa

Please sign in to comment.