-->

import play.Project in Play 2.3 not working

2019-09-05 07:13发布

问题:

In an older Play app (v 2.2.x) I have the following in my Build.scala

import play.Project._

In v.2.3 this is not compiling

Is there any reason for this based on the version?

回答1:

See the migration guide

https://www.playframework.com/documentation/2.3.x/Migration23 - scroll down to Build Changes

Near: "If you were previously using play.Project, for example a Scala project [...] then you can continue to use a similar approach via native sbt"



回答2:

Need to take care while migrating - in Build.scala

In Play 2.2

import sbt._
import Keys._
import PlayProject._

Migrate to Play 2.3, add the followings

import play.Play.autoImport._
import PlayKeys._

Remove import PlayProject._

Add also

If Java Project

val main = Project(appName, file(".")).enablePlugins(play.PlayJava).settings( version := appVersion, libraryDependencies ++= appDependencies )

If Scala Project

val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings( version := appVersion, libraryDependencies ++= appDependencies )

Instead of

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings()

Don't need to add the scalaVersion := "2.11.1" in Build.scala or build.sbt file as suggested in the Play 2.3 Migration Guide. In Play 2.2 the Build.scala or build.sbt file structure is different.