Reputation: 103
We have our Playframework tests setup with fakeApplication using GuiceApplicationBuilder
class BaseSpec extends AnyFunSpec/PlaySpec with GuiceOneAppPerSuite {
override def fakeApplication(): Application = new GuiceApplicationBuilder()
.disable[PlayModule]
.disable[JobSchedulerModule]
.build()
}
We have our (sanitized) tests setup like
import BaseSpec
class SampleSpec extends BaseSpec {
"test suite" should {
"test case" in {
.....
}
}
}
Whenever we run our tests, we get:
A needed class was not found. This could be due to an error in your runpath. Missing class: play/Configuration
java.lang.NoClassDefFoundError: play/Configuration
at play.inject.BuiltInModule.bindings(BuiltInModule.java:22)
at play.api.inject.guice.GuiceableModuleConversions.guice(GuiceInjectorBuilder.scala:365)
at play.api.inject.guice.GuiceableModuleConversions.guice$(GuiceInjectorBuilder.scala:364)
Versions: sbt: 1.6.0-M1 jdk: 11.0.24 sbt-play: 2.8.8 scala-sbt: 2.12.15
scalaVersion := "2.12.15"
val akkaVersion = play.core.PlayVersion.akkaVersion
libraryDependencies ++= Seq(
guice,
ws,
"org.skinny-framework" %% "skinny-orm" % "3.1.0" withSources(),
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.5"withSources(),
"org.scalikejdbc" %% "scalikejdbc" % "3.3.1" withSources(),
"com.typesafe.play" %% "play-slick" % "5.0.2" withSources(),
"com.auth0" % "java-jwt" % "3.2.0", // Don't update it! will have jackson conflict
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
"org.scalatestplus" %% "mockito-5-12" % "3.2.19.0" % Test,
"org.mockito" % "mockito-all" % "1.10.19" % Test,
"com.amazonaws" % "aws-java-sdk" % "1.11.313",
"org.flywaydb" %% "flyway-play" % "7.14.0",
"org.postgresql" % "postgresql" % "42.2.2",
"com.chuusai" %% "shapeless" % "2.3.3",
"org.typelevel" %% "cats-core" % "1.1.0",
"org.lyranthe.prometheus" %% "client" % "0.9.0-M5",
"io.split.client" % "java-client" % "2.3.1",
"com.segment.analytics.java" % "analytics" % "2.1.0",
"it.innove" % "play2-pdf" % "1.9.1",
"org.webjars" % "swagger-ui" % "2.2.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.11.4",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.11.4",
"com.github.jasminb" % "jsonapi-converter" % "0.11",
"de.leanovate.play-mockws" %% "play-mockws" % "2.8.1" % Test,
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"javax.xml.bind" % "jaxb-api" % "2.3.1",
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-library" % scalaVersion.value,
"com.typesafe.play" %% "play" % "2.8.8",
"com.typesafe.play" %% "play-guice" % "2.8.8",
"com.typesafe.play" %% "play-test" % "2.8.8" % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http" % "10.2.10" % Test
)
dependencyOverrides ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion withSources(),
"com.typesafe.akka" %% "akka-stream" % akkaVersion withSources(),
"com.google.guava" % "guava" % "22.0",
"org.slf4j" % "slf4j-api" % "2.0.16",
"org.bitbucket.b_c" % "jose4j" % "0.7.0",
)
The tests that do not require the fake app do not throw this exception. This exception is a result of us trying to upgrade our app from an older version. We tried altering the logic for GuiceOneAppPerSuite, but it doesnt work. We tried upgrading the version of PlayFramework, it still doesnt work. We can confirm that play/configuration is part of our runpath.
Upvotes: 0
Views: 31
Reputation: 15050
The error makes me think you're using the Java imports instead of the Scala ones. Some classes of Play are available both for Java and Scala under different packages.
Same goes for the Configuration
class. You want the play.api.xxx
classes (notice the api
).
Check your import
s statements.
Upvotes: 1