sbt 子项目的项目目录

rog*_*one 5 scala sbt

sbt 子项目可以有自己的project目录吗?或者只有根项目可以使用 .scala 帮助文件为构建项目目录?。下面是我目前的构建结构。在/my-project/sub-projects/sub-project-1/build.sbt无法定义访问对象/my-project/sub-projects/sub-project-1/SubProjectHelper.scala

/my-project
  build.sbt
  /projects
    Helper.scala
  sub-projects
    sub-project-1
      build.sbt
      /projects
        SubProjectHelper.scala
Run Code Online (Sandbox Code Playgroud)

更新: sub-project-1/build.sbt 中的以下 sbt 定义

lazy val localhost = (project in file(".")).settings (
    name := """localhost""",
    version := Common.version,
    scalaVersion := Common.scalaVersion,
    libraryDependencies ++= Common.dependencies,
    libraryDependencies ++= Localhost.dependencies
)
Run Code Online (Sandbox Code Playgroud)

因以下错误而失败

    libraryDependencies ++= Localhost.dependencies
                            ^
sbt.compiler.EvalException: Type error in expression
    at sbt.compiler.Eval.checkError(Eval.scala:384)
    at sbt.compiler.Eval.compileAndLoad(Eval.scala:183)
    at sbt.compiler.Eval.evalCommon(Eval.scala:152)
    at sbt.compiler.Eval.evalDefinitions(Eval.scala:122)
    at sbt.EvaluateConfigurations$.evaluateDefinitions(EvaluateConfigurations.scala:271)
    at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:109)
    at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:712)
Run Code Online (Sandbox Code Playgroud)

Common 定义在 /my-project/projects/Common.scala 中并且没有问题。但是Localhost定义在/my-project/sub-projects/sub-project-1/projects/SubProjectHelper.scala在sub-project-1 build.sbt中没有正确解析

ka4*_*eli 0

是的,他们可以,你甚至不需要有sub-projectsdir,只需放在dirsub-project-1中即可。my-project