rogue-one
rogue-one

Reputation: 11587

project directory for sbt sub-projects

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

Upvotes: 5

Views: 1074

Answers (3)

David Illing
David Illing

Reputation: 1

The answer is no, unfortunately. As seen here

You cannot have a project subdirectory or project/*.scala files in the sub-projects. foo/project/Build.scala would be ignored.

Upvotes: 0

seblm
seblm

Reputation: 370

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.

Upvotes: 0

ka4eli
ka4eli

Reputation: 5424

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

Upvotes: 0

Related Questions