2

How can I share the definition of a Simple Build Tool module project
between many parent projects?
and at the same time
include the module project definition in each parent project build file?

Clarification:

I have a parent project, and a Dao module project and a App module project and a Core project. Both module projects (i.e. Dao and App) depend on (the exact same version of) Core:

Parent project
  |
  |--> app
  |     `--> core
  |
  `--> dao
        `--> core

I defined App, Dao and Core in their own project directories, (as described here)
so they can be resued by many parent projects.
However, when I load the parent project, SBT gives this error:

The same directory is used for output for multiple projects

So instead I copied the App, Dao and Core project definitions into the parent project definition. That is, declared all projects and their dependencies in the single build file of the parent project.

Now everything works fine.

However, I have many parent projects. Each parent project uses different versions of the App project and the Dao project. (DAO = Data Access Object -- e.g. database storage or file storage, varies from project to project.)

So I'd need to repeat the definitions of App and Dao in each parent project, to avoid the The same directory is used for output for multiple projects error. But the result would be lots of duplicated project build code!

How can I avoid this?

I have one idea: Perhaps I can create a module for e.g. the Dao project, with a trait that declares all Dao's dependencies (on 3rd party libraries). Then there would be almost no duplicated code, only the dependency from Dao on Core would be repeated in each parent project.

What do you think?
Do you perhaps have some other ideas?

KajMagnus
  • 11,308
  • 15
  • 79
  • 127

1 Answers1

4

Putting project dependencies in a trait, and mixing it in on demand is one of the options.

However, I'd suggest you to look into SBT 0.10 (you will anyway will have to migrate to it one day). In a new SBT it can be done as easy as

import sbt._

object RootProject extends Build
{
        lazy val projects = Seq(root, core, dao, app)

        override val root = Project("root", file(".")) aggregate(core, dao, app)
        lazy val core  = Project("core", file("core"))
        lazy val app  = Project("app", file("app")) dependsOn(core)
        lazy val dao = Project("dao", file("dao")) dependsOn(core)
}

,where any project - core, app, dao - could be a standalone one with it's own settings and dependencies.

Community
  • 1
  • 1
Vasil Remeniuk
  • 20,519
  • 6
  • 71
  • 81
  • 2
    I didn't expect such a lovely solution! (I.e. SBT 0.10) Thanks. Here is a link to the SBT 0.10 docs on the `aggregate` and the `dependsOn` stuff: https://github.com/harrah/xsbt/wiki/Full-Configuration – KajMagnus Jun 10 '11 at 19:10