How to System.setProperty in sbt 0.11.x

727 views
Skip to first unread message

fmpwizard

unread,
Mar 30, 2012, 10:04:52 AM3/30/12
to simple-b...@googlegroups.com
Hi,

I'm using the build.sbt format for my build files and after a lot of searching all over the place  I finally found that to use
System.setProperty 
you use

initialize ~= { _ => System.setProperty("OPTIONS","plus,ext.default" ) }

Now, how was I supposed to "learn" or "know" this? I tried searching the wiki but that gave me no results, or maybe I missed some important section. I'm asking because I would think that this is a common thing to do, but took me a while to get it working.

Probably because I knew how to setup a property for test runs, which I use:

testOptions in Test += Tests.Setup( () => System.setProperty("run.mode", "test"))


so I was looking for something like:

runTimeOptions in RunTime += Runtime.Setup( () => System.setProperty("blah", "run"))

Again, I'm posting this so that I can learn where I'm supposed to look for information.

Thanks

  Diego

Paul Phillips

unread,
Mar 30, 2012, 12:14:13 PM3/30/12
to simple-b...@googlegroups.com
On Fri, Mar 30, 2012 at 7:04 AM, fmpwizard <fmpw...@gmail.com> wrote:
> I'm using the build.sbt format for my build files and after a lot of
> searching all over the place  I finally found that to use
> System.setProperty
> you use
>
> initialize ~= { _ => System.setProperty("OPTIONS","plus,ext.default" ) }
>
> Now, how was I supposed to "learn" or "know" this?

If one anticipates expanding the build tool audience to include
humans, one could add something like this to the standard Build.scala:

import sbt._
import Keys._

object MisterBuild extends Build {
def init(body: => Unit) = initialize ~= (_ => body)

lazy val dummyProjectToPleaseSbt = Project("proj", file("."))
}

After which one could do this in build.sbt to set properties or whatever else.

// that's the whole build.sbt
init {
sys.props("OPTIONS") = "plus,ext.default"
sys.props("BIPPY") = "I'm bippy!"
// Look ma, no blank lines
println("And I don't even need blank lines!")
}

Brent Gracey

unread,
Nov 16, 2012, 6:21:19 AM11/16/12
to simple-b...@googlegroups.com
Hi - think this is a similar question. I've need to set the below props, but I am using a mutli project, build.scala file, not a .sbt file

initialize ~= { _ =>
  System.setProperty("DEBUG.MONGO", "true")
  System.setProperty("DB.TRACE", "true")
}

Below is a extract of my build.scala - which objects do I need to update to set the system properties (or am I completely on the wrong track)



object SBuild extends Build {

  lazy val buildSettings = Seq(
    organization := "com",
    version := "1.1-SNAPSHOT",
    scalaVersion := "2.9.1"
  )

  lazy val root = Project(
    id = "root",
    base = file("."),
    settings = defaultSettings ++ containerSettings,
    aggregate = Seq(db, admin, manager, reg, user)
  )

  lazy val db = Project(
    id = "db",
    base = file("sojo_database"),
    settings = dbSettings ++ Seq(
      description := "sojo database layer"
    )
  )

  ......


  lazy val dbSettings = defaultSettings ++ Seq(
    libraryDependencies ++= Dependencies.liftDbPackages,
    libraryDependencies ++= Dependencies.dbPackages,
    libraryDependencies ++= Dependencies.loggingPackages
  ) ++ testSettings

  .......

object Dependencies {
  val liftVersion = "2.4" // Put the current/latest lift version here

  val liftPackages = Seq(
    "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
    "net.liftweb" %% "lift-widgets" % liftVersion % "compile->default"
  )

.....


Mark Harrah

unread,
Nov 16, 2012, 11:40:50 AM11/16/12
to simple-b...@googlegroups.com
On Fri, 16 Nov 2012 03:21:19 -0800 (PST)
Brent Gracey <brent...@gmail.com> wrote:

> Hi - think this is a similar question. I've need to set the below props,
> but I am using a mutli project, build.scala file, not a .sbt file
>
> initialize ~= { _ =>
> System.setProperty("DEBUG.MONGO", "true")
> System.setProperty("DB.TRACE", "true")
> }
>
> Below is a extract of my build.scala - which objects do I need to update to
> set the system properties (or am I completely on the wrong track)
>
>
>
> object SBuild extends Build {

You can put the setProperty calls directly here. SBuild is a normal Scala module and so any initialization statements will get evaluated when the project is loaded. `initialize` is a hack to all initialization statements in a .sbt file or to allow the initialization to access values of settings.

> lazy val buildSettings = Seq(
> organization := "com",
> version := "1.1-SNAPSHOT",
> scalaVersion := "2.9.1"
> )
>
> lazy val root = Project(
> id = "root",
> base = file("."),
> settings = defaultSettings ++ containerSettings,

Or, if you want to keep using `initialize`, you can append it to the settings of the root project, which is where settings from a .sbt file would go:

settings = defaultSettings ++ containerSettings ++ Seq(
initialize ~= ...
)

-Mark

> aggregate = Seq(db, admin, manager, reg, user)
> )
>
> lazy val db = Project(
> id = "db",
> base = file("sojo_database"),
> settings = dbSettings ++ Seq(
> description := "sojo database layer"
> )
> )
>
> ......
>
>
> lazy val dbSettings = defaultSettings ++ Seq(
> libraryDependencies ++= Dependencies.liftDbPackages,
> libraryDependencies ++= Dependencies.dbPackages,
> libraryDependencies ++= Dependencies.loggingPackages
> ) ++ testSettings
>
> .......
>
> object Dependencies {
> val liftVersion = "2.4" // Put the current/latest lift version here
>
> val liftPackages = Seq(
> "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
> "net.liftweb" %% "lift-widgets" % liftVersion % "compile->default"
> )
>
> .....
>
>
>
> On Friday, March 30, 2012 5:14:13 PM UTC+1, Paul Phillips wrote:
> >
> > On Fri, Mar 30, 2012 at 7:04 AM, fmpwizard <fmpw...@gmail.com<javascript:>>
> > wrote:
> > > I'm using the build.sbt format for my build files and after a lot of
> > > searching all over the place I finally found that to use
> > > System.setProperty
> > > you use
> > >
> > > initialize ~= { _ => System.setProperty("OPTIONS","plus,ext.default" ) }
> > >
> > > Now, how was I supposed to "learn" or "know" this?
> >
> > If one anticipates expanding the build tool audience to include
> > humans, one could add something like this to the standard Build.scala:
> >
> > import sbt._
> > import Keys._
> >
> > object MisterBuild extends Build {
> > def init(body: => Unit) = initialize ~= (_ => body)
> >
> > lazy val dummyProjectToPleaseSbt = Project("proj", file("."))
> > }
> >
> > After which one could do this in build.sbt to set properties or whatever
> > else.
> >
> > // that's the whole build.sbt
> > init {
> > sys.props("OPTIONS") = "plus,ext.default"
> > sys.props("BIPPY") = "I'm bippy!"
> > // Look ma, no blank lines
> > println("And I don't even need blank lines!")
> > }
> >
> >
>
> --
> 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/-/tys6en_ye4EJ.
> 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.
>

Reply all
Reply to author
Forward
0 new messages