Configuring sub-projects in sbt 0.10

247 views
Skip to first unread message

Stuart Roebuck

unread,
Jun 10, 2011, 5:57:39 AM6/10/11
to simple-b...@googlegroups.com
Can someone point me to an explanation of setting up subprojects under 0.10.   I confess I didn't know how to do it under 0.7 either so ideally it would be documentation that doesn't assume the latter!

I've done some searching but all I can find is some largish examples that have sub project dependencies, but it's not clear to me how much of the configuration in those examples is extra stuff and how much is what is fundamentally required.  In short, my brain is fried and I'm stuck!

Ideally there might be a way of declaring sub-project dependencies in a build.sbt file, but I think I've already read that that isn't possible.

Cheers,

Stuart.

Christopher Turner

unread,
Jun 10, 2011, 6:21:22 AM6/10/11
to simple-b...@googlegroups.com
Hi,
I managed to get this working yesterday on a simple project with two sub projects. In the end I went down the route of creating a project/Build.scala file with the following contents:

import sbt._
import Keys._

object BuildSettings {
  val buildOrganization = "mycompany"
  val buildScalaVersion = "2.9.0-1"
  val buildVersion      = "0.3.0"

  val buildSettings = Defaults.defaultSettings ++ Seq (organization := buildOrganization,
                                           scalaVersion := buildScalaVersion,
                                           version      := buildVersion)
}

object Dependencies {
  val xerces = "xerces" % "xercesImpl" % "2.8.1" % "compile"
  val slf4j = "org.slf4j" % "slf4j-api" % "1.6.1" % "compile"  
  val logback = "ch.qos.logback" % "logback-classic" % "0.9.28" % "compile"
  val slf4s = "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.6"

  val specs2 = "org.specs2" %% "specs2" % "1.3" % "test"
  val scalacheck = "org.scala-tools.testing" %% "scalacheck" % "1.9" % "test"

  val compileDeps = Seq(xerces, slf4j, logback, slf4s)
  val testDeps = Seq(specs2, scalacheck)
  val allDeps = compileDeps ++ testDeps
}

object MyUtilsBuild extends Build {
  import Dependencies._
  import BuildSettings._

  lazy val myUtils = Project ("my-utils", file ("."), 
           settings = buildSettings) aggregate (myCMS, myTools)


  lazy val myCMS = Project ("my-cms", file ("my-cms"),
           settings = buildSettings ++ Seq (libraryDependencies := allDeps))
           
  lazy val myTools = Project ("my-tools", file ("my-tools"),
           settings = buildSettings) dependsOn (myCMS)
}


Hope that helps.
Chris


--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/sN6TfOaSmekJ.
To post to this group, send email to simple-b...@googlegroups.com.
To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

Stuart Roebuck

unread,
Jun 10, 2011, 9:54:22 AM6/10/11
to simple-b...@googlegroups.com
Chris,

Many thanks.

This is getting me much closer to understanding what's going on...

questions?...

Is this "Build.scala" build file effectively acting as a multiple build file for this project and the sub-projects or do the sub-projects also have their own build files?

If they do have their own build files then why is this build file apparently setting the library dependencies for the "my-cms" project?  Do the Project settings parameter values override the settings in the sub-projects?

I'll try and do another pass through the documentation and see if I can find where it explains the Project class.

Stuart.

ijuma

unread,
Jun 10, 2011, 10:00:24 AM6/10/11
to simple-b...@googlegroups.com
On Friday, 10 June 2011 14:54:22 UTC+1, Stuart Roebuck wrote:
Is this "Build.scala" build file effectively acting as a multiple build file for this project and the sub-projects or do the sub-projects also have their own build files?

Both approaches are possible. You can have a single Build.scala that configures the project dependencies and then one *.sbt file for each subproject settings or you can configure everything in Build.scala.

Best,
Ismael

Stuart Roebuck

unread,
Jun 10, 2011, 10:02:47 AM6/10/11
to simple-b...@googlegroups.com
Ismael,

Which one of these is Chris's example?

Stuart <-- probably being less than intelligent today!

Heiko Seeberger

unread,
Jun 10, 2011, 10:21:27 AM6/10/11
to simple-b...@googlegroups.com
Hi Stuart,

In Chris' example there is one Build.scala file that configures the whole build with its multiple projects.

In the example project(s) for the sbteclipse plugin I have chosen a similar setup: https://github.com/typesafehub/sbteclipse/tree/master/example

In order for you to get familiar with SBT 0.10 I recommend you take the same route. Using additional build.sbt files in one or more of the projects will possible lead to confusion, because the settings in these files will override the settings in Build.scala (as will settings entered in the interactive mode).

Heiko

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/cR6ssl419-4J.

To post to this group, send email to simple-b...@googlegroups.com.
To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.



--

Heiko Seeberger
Twitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the Experts


Stuart Roebuck

unread,
Jun 10, 2011, 10:38:43 AM6/10/11
to simple-b...@googlegroups.com
Heiko,

Thanks.

I think I may be using the wrong terminology which may explain why I'm not finding the answer.

In my case the sub-project is a stand alone project which provides functionality to a number of independent applications.  For the sake of this example, let's call it "my-web-library".

My main project is one of those applications, let's call it "my-web-app".

Currently I go to the my-web-library directory and use "sbt publish-local" to build and publish a copy of the library.  Then I go to my-web-app and "sbt run" to build and run the app.  Under sbt 0.7 I had to "sbt import run" because import was not automatic.

I would like to be able to go to my-web-app and "sbt run" in the knowledge that it would automatically build and include the resulting library from my-web-app.

I'm sure the answer is simple I just don't appear to be looking in the right place for the answer.

Stuart.

Heiko Seeberger

unread,
Jun 10, 2011, 10:42:22 AM6/10/11
to simple-b...@googlegroups.com
On 10 June 2011 16:38, Stuart Roebuck <stuart....@gmail.com> wrote:

Currently I go to the my-web-library directory and use "sbt publish-local" to build and publish a copy of the library.  Then I go to my-web-app and "sbt run" to build and run the app.  Under sbt 0.7 I had to "sbt import run" because import was not automatic.

Could it be true, that you are once again using the wrong terminology ;-)
import => update ?

Heiko

Stuart Roebuck

unread,
Jun 10, 2011, 10:45:02 AM6/10/11
to simple-b...@googlegroups.com
Yes indeed, my brain frequently substitutes words and omits others, it does lead to some unanticipated creative discoveries though!

Heiko Seeberger

unread,
Jun 10, 2011, 10:48:10 AM6/10/11
to simple-b...@googlegroups.com
On 10 June 2011 16:45, Stuart Roebuck <stuart....@gmail.com> wrote:
Yes indeed, my brain frequently substitutes words and omits others, it does lead to some unanticipated creative discoveries though!

LOL

Regarding your question: If you publish(-local) a snapshot release, I guess that SBT 0.10 will pick it up automagically, i.e. update will happen transparently. But if you publish "usual" artifacts I think that you have to run update manually.

Heiko

Mark Harrah

unread,
Jun 10, 2011, 10:53:08 AM6/10/11
to simple-b...@googlegroups.com
Hey Stuart,

On Fri, 10 Jun 2011 07:38:43 -0700 (PDT)
Stuart Roebuck <stuart....@gmail.com> wrote:

> Heiko,
>
> Thanks.
>
> I think I may be using the wrong terminology which may explain why I'm not
> finding the answer.
>
> In my case the sub-project is a stand alone project which provides
> functionality to a number of independent applications. For the sake of this
> example, let's call it "my-web-library".
>
> My main project is one of those applications, let's call it "my-web-app".
>
> Currently I go to the my-web-library directory and use "sbt publish-local"
> to build and publish a copy of the library. Then I go to my-web-app and
> "sbt run" to build and run the app. Under sbt 0.7 I had to "sbt import run"
> because import was not automatic.
>
> I would like to be able to go to my-web-app and "sbt run" in the knowledge
> that it would automatically build and include the resulting library from
> my-web-app.

I would suggest using external project support, which you can read about on the Full Configuration or see one of the several threads on it. This allows you to skip the publish-local in the my-web-library. You can just modify that project and when you do run in my-web-app, it will be automatically recompiled.

-Mark

Stuart Roebuck

unread,
Jun 10, 2011, 12:31:19 PM6/10/11
to simple-b...@googlegroups.com
Mark,

Thanks.  I've looked through some of the documentation again and I am unfortunately lost.

I think the relevant bit of the documentation is the "Full Configuration" reference to "Classpath Dependencies".

So I think I need to create a file project/Build.scala in my my-web-app project something like:

  import sbt._

  object MyBuild extends Build
  {
    lazy val a = Project( [somehow define my-web-app hopefully with reference to the working build.sbt file] ) dependsOn(b)
    lazy val b = RootProject( file("[absolute path to my-web-library project directory]") )
    lazy val projects = Seq(a)
  }

If this is basically correct then all I need is to figure out how to refer to the project configuration details already specified in the build.sbt file.

Stuart

Heiko Seeberger

unread,
Jun 10, 2011, 1:44:14 PM6/10/11
to simple-b...@googlegroups.com
Hi Stu,

Build.scala and build.sbt can coexist. If for example your Build.scala just references the external build (like below) and your build.sbt configures, say, organization, name, scalaVersion, dependencies, etc. you will be fine.

Heiko


Stuart

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/GGGG-4CeDaAJ.

To post to this group, send email to simple-b...@googlegroups.com.
To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

Stuart Roebuck

unread,
Jun 10, 2011, 1:56:17 PM6/10/11
to simple-b...@googlegroups.com
Heiko,

That's promising, but what do I put between the brackets in the declaration of a?

lazy val a = Project( [somehow define my-web-app hopefully with reference to the working build.sbt file] ) dependsOn(b)

Stuart

Heiko Seeberger

unread,
Jun 10, 2011, 2:05:44 PM6/10/11
to simple-b...@googlegroups.com
Assuming you are in your project root dir and have a build.sbt there:
lazy val a = Project("my-web-app", file("."))


Heiko

Stuart

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/1ixx4V3pOmMJ.

To post to this group, send email to simple-b...@googlegroups.com.
To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

Stuart Roebuck

unread,
Jun 10, 2011, 3:54:13 PM6/10/11
to simple-b...@googlegroups.com
Heiko / Mark / Ismael / Chris,

Many thanks.

It appears that this is all I needed:

  import sbt._

  object MyBuild extends Build
  {
    lazy val myWebApp = Project("my-web-app", file(".")) dependsOn(myWebLibrary)
    lazy val myWebLibrary = RootProject(file("../my-web-library"))
  }

This continues to use the my-web-app "build.sbt" file for all the other configuration and dependencies.  I removed from that the dependency on my-web-library as the above code takes that place.

However, this doesn't seem to match with the "Defining a Build" section on the "Full Configuration" wiki page.  That section indicates that a build primarily consists of a definition of the projects method, but when I included a projects method I got an error requiring me to override the existing projects and when I removed it completely everything worked fine.  I do know the ins and outs of why this is but it looks like that bit of documentation may benefit from a correction.

Anyway, thanks again for being patient with me :)

I'm thinking about the idea of writing some introduction to Full Configuration for people with brains the same shape as mine or maybe a page comparing the two configurations and showing equivalent configurations of each form side by side.  Do you think either of these ideas would make sense?

Stuart.

Mark Harrah

unread,
Jun 10, 2011, 9:10:05 PM6/10/11
to simple-b...@googlegroups.com
On Fri, 10 Jun 2011 12:54:13 -0700 (PDT)
Stuart Roebuck <stuart....@gmail.com> wrote:

> Heiko / Mark / Ismael / Chris,
>
> Many thanks.
>
> It appears that this is all I needed:
>
> import sbt._
>
> object MyBuild extends Build
> {
> lazy val myWebApp = Project("my-web-app", file("."))
> dependsOn(myWebLibrary)
> lazy val myWebLibrary = RootProject(file("../my-web-library"))
> }
>
> This continues to use the my-web-app "build.sbt" file for all the other
> configuration and dependencies. I removed from that the dependency on
> my-web-library as the above code takes that place.
>
> However, this doesn't seem to match with the "Defining a Build" section on
> the "Full Configuration" wiki page. That section indicates that a build
> primarily consists of a definition of the projects method, but when I
> included a projects method I got an error requiring me to override the
> existing projects and when I removed it completely everything worked fine.
> I do know the ins and outs of why this is but it looks like that bit of
> documentation may benefit from a correction.

Yeah, sorry. All of the other sections were updated but that one. I deleted it.

-Mark

Reply all
Reply to author
Forward
0 new messages