简体   繁体   English

在Play 2.6.3项目的根文件夹中找不到非Play Sbt Scala子项目

[英]non-Play Sbt Scala sub-project not found in root folder of Play 2.6.3 project

I used the Gitter Play Scala Seed template to create a starter project. 我使用Gitter Play Scala Seed模板创建了一个入门项目。 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. 但是,即使我添加了子项目文件夹并从build.sbt文件中引用了它,但是每当我运行update (或其任何依赖项)时,我都会收到一条错误消息,指出找不到子项目。

Here's the build.sbt which I am using in the play project (my base project) folder: 这是我在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"

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. 我在我的lettergenerator使用的是sbt版本0.13.16Scala 2.12.3 ,但是我分别为play项目的build.sbt尝试了这两个版本以及0.13.15 / 2.12.2

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. 我可能遗漏了一些明显的内容,但到目前为止,我不确定我还能做什么,因此将不胜感激。

I think you need to point lettergenerator to the right sub-directory of your project, ie, replace 我认为您需要将lettergenerator指向lettergenerator的正确子目录,即替换

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. 对于多个子项目,我建议从默认的播放布局切换到默认的SBT布局 ,并将播放应用程序也移动到单独的子目录中,即backendserver

I also advise against having multiple build.sbt files for different sub-projects. 我还建议不要为不同的子项目使用多个build.sbt文件。 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 . 相反,我建议保留一个顶级build.sbt并在.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 ). 对于影响整个项目的通用设置,例如version ,我在root项目( 简单示例更复杂的实际示例 )上使用.settings(inThisBuild(…)) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM