0

I used the Gitter Play Scala Seed template to create a starter project. I later decided to add another one of my projects as a sub-project to this one by following these and these instructions. However, even though I added the sub-project folder and referred to it from my build.sbt file, whenever I run update (or any of its dependencies) I am getting an error saying that the sub-project cannot be found.

Here's the build.sbt which I am using in the play project (my base project) folder:

name := """play-scala-starter-example"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file("."))
    .enablePlugins(PlayScala)
    .aggregate(lettergenerator)
    .dependsOn(lettergenerator)

// I have also tried it explicitly:
// lazy val lettergenerator = (project in file("lettergenerator"))
lazy val lettergenerator = project

resolvers += Resolver.sonatypeRepo("snapshots")

scalaVersion := "2.12.2"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.0.0" % Test
libraryDependencies += "com.h2database" % "h2" % "1.4.194"

This is my folder structure:

play-scala-starter-example
 ├ app
 ├ build.sbt
 ├ conf
 ├ lettergenerator
 │  ├ build.sbt
 │  ├ LICENSE
 │  ├ project
 │  ├ README.md
 │  ├ src
 │  └ TODO.md
 ├ LICENSE
 ├ logs
 ├ project
 ├ public
 ├ README.md
 ├ target
 └ test

Here's the stack trace from the error:

[info] Loading global plugins from /home/claudiusbr/.sbt/0.13/plugins
[info] Loading project definition from /home/claudiusbr/test/play-scala-starter-example/project
java.lang.RuntimeException: No project 'lettergenerator' in 'file:/home/claudiusbr/test/play-scala-starter-example/'.
Valid project IDs: root
        at scala.sys.package$.error(package.scala:27)
        at sbt.Load$$anonfun$checkAll$2$$anonfun$apply$16.apply(Load.scala:401)
        at sbt.Load$$anonfun$checkAll$2$$anonfun$apply$16.apply(Load.scala:396)
        at scala.collection.immutable.List.foreach(List.scala:318)
        at sbt.Load$$anonfun$checkAll$2.apply(Load.scala:396)
        at sbt.Load$$anonfun$checkAll$2.apply(Load.scala:396)
        at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
        at scala.collection.immutable.Map$Map1.foreach(Map.scala:109)
        at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
        at sbt.Load$.checkAll(Load.scala:396)
        at sbt.Load$.loadURI(Load.scala:321)
        at sbt.Load$.load(Load.scala:316)
        at sbt.Load$.load(Load.scala:305)
        at sbt.Load$$anonfun$4.apply(Load.scala:146)
        at sbt.Load$$anonfun$4.apply(Load.scala:146)
        at sbt.Load$.timed(Load.scala:1025)
        at sbt.Load$.apply(Load.scala:146)
        at sbt.Load$.defaultLoad(Load.scala:39)
        at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:548)
        at sbt.BuiltinCommands$.doLoadProject(Main.scala:548)
        at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:540)
        at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:540)
        at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
        at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
        at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
        at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
        at sbt.Command$.process(Command.scala:93)
        at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
        at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
        at sbt.State$$anon$1.doX$1(State.scala:183)
        at sbt.State$$anon$1.process(State.scala:190)
        at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
        at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.MainLoop$.next(MainLoop.scala:96)
        at sbt.MainLoop$.run(MainLoop.scala:89)
        at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
        at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
        at sbt.Using.apply(Using.scala:24)
        at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
        at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
        at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
        at sbt.MainLoop$.runLogged(MainLoop.scala:22)
        at sbt.StandardMain$.runManaged(Main.scala:109)
        at sbt.xMain.run(Main.scala:38)
        at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
        at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
        at xsbt.boot.Launch$.run(Launch.scala:109)
        at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
        at xsbt.boot.Launch$.launch(Launch.scala:117)
        at xsbt.boot.Launch$.apply(Launch.scala:18)
        at xsbt.boot.Boot$.runImpl(Boot.scala:41)
        at xsbt.boot.Boot$.main(Boot.scala:17)
        at xsbt.boot.Boot.main(Boot.scala)
[error] No project 'lettergenerator' in 'file:/home/claudiusbr/test/play-scala-starter-example/'.
[error] Valid project IDs: root
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

I have tried looking at what seems to be a similar question for a different error, but nothing I can see there seems to help with my issue.

I am using sbt version 0.13.16 and Scala 2.12.3 for my lettergenerator, but I tried respectively both these and 0.13.15/2.12.2 for my play project's build.sbt and neither worked.

It's possible I am missing something obvious, but so far I am not sure what else I could do, so would appreciate any assistance.

Claudius
  • 156
  • 1
  • 11
  • What is the output of *projects* command in sbt console? – jrook Aug 22 '17 at 01:21
  • It doesn't get to the console, actually. It seems to be an update error, so it does not get to resolve all the necessary dependencies to go into the console. – Claudius Aug 22 '17 at 06:08

1 Answers1

1

I think you need to point lettergenerator to the right sub-directory of your project, ie, replace

lazy val lettergenerator = project

with

lazy val lettergenerator = project.in(file("lettergenerator"))

With multiple sub-projects I recommend to switch from the default play layout to the default SBT layout and move the play application into a separate sub-directory as well, ie, backend or server or whatever.

I also advise against having multiple build.sbt files for different sub-projects. In my experience this doesn't scale well and quickly becomes confusing as sub-projects become more complex.

Instead I recommend to keep a single top-level build.sbt and define all settings per-project in .settings. For common settings that affect the whole project, eg, version, I use .settings(inThisBuild(…)) on the root project (simple example, or more complex real world example).

  • I tried that also (declaring it explicitly rather than letting it infer from the variable name), but it still did not work. I will have to try the sub-project option later, as this is a non-work related project, so I'll post the results here when I do. – Claudius Aug 22 '17 at 08:06
  • Ok, so I looked into it and, although the alternate solution of making the Play project the sub-project will be very helpful for future projects (hence the upvote), I cannot make the standard sbt one the base project in this particular instance as I can't see a scenario where I would be able to do this without changing the build.sbt file for it. The standard one should not be coupled to the Play one, only the other way around. It does seem to me that the documentation implies that this is (or should be) possible, so I would like to try to find a solution which allows me to keep it this way. – Claudius Aug 22 '17 at 19:00
  • 1
    After moving both projects to separate folders nested within another root project, Sbt found my lettergenerator. It does look like the issue was related to the build.sbt file, like you suggested. I'm getting another exception now, but at least the project is compiling. Thanks your help. – Claudius Aug 22 '17 at 21:01