I have a play project that I'd like to build with a common
library that handles things like clients, services, utilities, etc...
My dir structure is like so:
.
├── build.sbt
├── myapp
│ ├── app
│ │ ├── controllers
│ │ │ └── HomeController.scala
│ │ └── views
│ │ ├── index.scala.html
│ │ └── main.scala.html
│ ├── conf
│ │ ├── application.conf
│ │ ├── logback.xml
│ │ ├── messages
│ │ └── routes
│ ├── public
│ │ ├── images
│ │ │ └── favicon.png
│ │ ├── javascripts
│ │ │ └── main.js
│ │ └── stylesheets
│ │ └── main.css
│ └── test
│ └── controllers
│ └── HomeControllerSpec.scala
├── myapp-common
│ └── src
│ └── main
│ └── TesterObject.scala
└── project
├── build.properties
├── plugins.sbt
└── scaffold.sbt
My build.sbt is configured as follows:
lazy val commonSettings = Seq(
version := "1.0-SNAPSHOT",
scalaVersion := "2.12.3"
)
lazy val root = (project in file("."))
.settings(commonSettings)
.aggregate(myapp, `myapp-common`)
.dependsOn(myapp, `myapp-common`)
lazy val `myapp-common` = project
.settings(commonSettings)
lazy val myapp = project
.enablePlugins(PlayScala)
.settings(commonSettings)
.settings(libraryDependencies += guice)
.settings(libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test)
.dependsOn(`myapp-common`)
While I am able to successfully run the play project with sbt myapp/run
, it fails when I try to import a package defined in myapp-common
.
For instance, if I have myapp-common/src/main/TesterObject.scala
:
package tester
Object TesterObject {
val testMe = 3
}
If I try to import tester._
and then use TesterObject.testMe
in myapp/app/controllers/HomeController.scala
, the project fails during compilation since it can't find the package.
Can anyone point me in the right direction here? The sbt guide on multi-projects is a bit tough for me to parse for this particular problem. It seems like my dependencies are appropriately set up.