My play framework application is all of a sudden throwing the following errors during compilation:
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:5:14: object inject is not a member of package javax
[error] import javax.inject._
[error] ^
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:11:2: trait Singleton is abstract; cannot be instantiated
[error] @Singleton
[error] ^
[error] /Users/ihorton/Client Work/DPaaS/coursera-scala/cookbook/app/controllers/HomeController.scala:12:23: not found: type Inject
[error] class HomeController @Inject()(controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) {
[error] ^
^
Here is my use of javax.inject
, @Inject
and @Singleton
in code:
import javax.inject._
@Singleton
class RecipeController @Inject()(controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) {
...
I've read through what looks to be the same issue here, but trying sbt reload
prior to compile
doesn't work for me.
What's puzzling, unless I'm misreading the Play Framework 2.8.x documentation, is that it seems like javax.inject should be packaged with Play out of the box. So I'm not sure why this object would be missing.
I'm using the following versions:
- Play: 2.8.8
- Scala: 2.13.6
- JDK: 17.0.1
Here's my build.sbt file to which I've added javax.inject
which doesn't seem to resolve the issue.
name := """cookbook"""
organization := "com.ian-horton"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.6"
libraryDependencies ++= Seq(
guice,
"commons-io" % "commons-io" % "2.5",
"javax.inject" % "javax.inject" % "1",
"net.sourceforge.tess4j" % "tess4j" % "5.0.0",
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
"org.specs2" %% "specs2-core" % "4.13.0" % Test)
Happy to provide additional detail if need be.
Thanks in advance!
Update
Finding this other Stack Overflow Question I followed the steps manually added the Maven dependency for Javax.Inject to my project in Intellij which fixed the problem.
I'm keeping this question open though in the hopes that someone can perhaps shed some light on why this dependency isn't pulled in with Play.