I have trouble compile the intellij play generated code with “not found AbstractController” and more. I have no idea what’s going on. Any ideas? Please help. thanks.
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:4: object inject is not a member of package javax
import javax.inject._
^
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type AbstractController
class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
^
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:20: trait Singleton is abstract; cannot be instantiated
@Singleton
^
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type ControllerComponents
class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
^
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type Inject
class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
^
/Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:32: not found: value Ok
getFutureMessage(1.second).map { msg => Ok(msg) }
Here’s the build.gradle file. I downloaded the latest gradle version. I am not sure if gradle supports the latest version of scala 2.12 and Play 2.6.6? And also should I specify the version in build.gradle?
build.gradle
repositories {
jcenter()
maven {
name "typesafe-maven-release"
url "https://repo.typesafe.com/typesafe/maven-releases"
}
ivy {
name "typesafe-ivy-release"
url "https://repo.typesafe.com/typesafe/ivy-releases"
layout "ivy"
}
}
apply plugin: "play"
apply plugin: "scala"
apply plugin: "idea"
model {
components {
play {
platform play: '2.6.6', scala: '2.12'
injectedRoutesGenerator = true
}
}
}
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
Here’s the AsyncController class generated by Intellij.
package controllers
import akka.actor.ActorSystem
import javax.inject._
import play.api._
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration._
/**
* This controller creates an `Action` that demonstrates how to write
* simple asynchronous code in a controller. It uses a timer to
* asynchronously delay sending a response for 1 second.
*
* @param actorSystem We need the `ActorSystem`'s `Scheduler` to
* run code after a delay.
* @param exec We need an `ExecutionContext` to execute our
* asynchronous code.
*/
@Singleton
class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
/**
* Create an Action that returns a plain text message after a delay
* of 1 second.
*
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/message`.
*/
def message = Action.async {
getFutureMessage(1.second).map { msg => Ok(msg) }
}
private def getFutureMessage(delayTime: FiniteDuration): Future[String] = {
val promise: Promise[String] = Promise[String]()
actorSystem.scheduler.scheduleOnce(delayTime) { promise.success("Hi!") }
promise.future
}
}