5
votes

can a sbt sub project have its own project directory? or only the root project can project directory with .scala helper files for the build?. Below is my current build scructure. The /my-project/sub-projects/sub-project-1/build.sbt is not able to access objects defined in /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

Update: The below sbt definition in sub-project-1/build.sbt

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

is failing with the below error

    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)

Common is defined in /my-project/projects/Common.scala and has no issues. But Localhost is defined in /my-project/sub-projects/sub-project-1/projects/SubProjectHelper.scala is not properly resolved in the sub-project-1 build.sbt

2

2 Answers

0
votes

Yes, they can, and you even don't need to have sub-projects dir, just place sub-project-1 in my-project dir.

0
votes

Usually (at least this is what scala/scala-seed.g8 ends up with) project subdirectory doesn't ends with an extra s like your directory structure.

You should rename projects to project.