我使用Gitter Play Scala Seed模板创建了一个初学者项目。
之后我决定按照these和these指示,将我的另一个项目作为子项目添加到此项目中。但是,即使我添加了子项目文件夹并从我的build.sbt
文件中引用它,每当我运行update
(或其任何依赖项)时,我都会收到错误消息,说明子项目无法找到。
这是我在play项目(我的基础项目)文件夹中使用的build.sbt
:
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"
这是我的文件夹结构:
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
以下是错误的堆栈跟踪:
[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
我试过看what seems to be a similar question for a different error,但我看不到任何东西似乎对我的问题有帮助。
我正在为sbt
使用0.13.16
版本Scala 2.12.3
和lettergenerator
,但我分别尝试了这两个版本和0.13.15
/ 2.12.2
我的play
项目的build.sbt
并没有效果。
我可能会遗漏一些显而易见的东西,但到目前为止,我不确定我还能做些什么,所以我将不胜感激。
答案 0 :(得分:1)
我认为您需要将lettergenerator
指向项目的正确子目录,即替换
lazy val lettergenerator = project
与
lazy val lettergenerator = project.in(file("lettergenerator"))
对于多个子项目,我建议从默认播放布局切换到default SBT layout,并将播放应用程序移动到单独的子目录中,即backend
或{{1}或者其他什么。
我还建议不要为不同的子项目提供多个server
文件。根据我的经验,这不能很好地扩展,并且随着子项目变得更加复杂,很快就会变得混乱。
相反,我建议保留一个顶级build.sbt
,并在build.sbt
中定义每个项目的所有设置。对于影响整个项目的常见设置,例如.settings
,我在version
项目simple example或more complex real world example上使用.settings(inThisBuild(…))
。