How do I make nscala-time available to sbt-buildinfo in my project/Build.scala?

762 views
Skip to first unread message

Robert Kuhar

unread,
Jun 17, 2013, 6:20:06 PM6/17/13
to simple-b...@googlegroups.com
I'm new to the whole Scala/SBT/Play stack and am struggling to figure out what is available to me and when.  My current challenge is to get the nscala-time available in my Build.scala so I can do a propert ISO-8601 timestamp of my build.  I add my appDependency but the compiler hates it...

bobk-mbp:dm2-server bobk$ play
[info] Loading project definition from /Users/bobk/work/dm2-server/project
[error] /Users/bobk/work/dm2-server/project/Build.scala:5: object github is not a member of package com
[error] import com.github.nscala_time.time.Imports._
[error]            ^
[error] one error found
[error] (compile:compile) Compilation failed
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

import sbt._
import Keys._
import play.Project._
import sbtbuildinfo.Plugin._
import com.github.nscala_time.time.Imports._

object ApplicationBuild extends Build {

  val appName = "dm2-server"
  val appVersion = "2.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
    javaCore,
    "org.slf4j" % "slf4j-api" % "1.7.5",
    "org.slf4j" % "jcl-over-slf4j" % "1.7.5",
    "org.slf4j" % "jul-to-slf4j" % "1.7.5",
    "ch.qos.logback" % "logback-classic" % "1.0.13",
    "com.github.nscala-time" %% "nscala-time" % "0.4.2",
    filters)

  val main = play.Project(
    appName,
    appVersion,
    appDependencies,
    settings = Defaults.defaultSettings ++ buildInfoSettings).settings(
      // Add your own project settings here
      // BuildInfo
      sourceGenerators in Compile <+= buildInfo,
      buildInfoKeys := Seq[BuildInfoKey](
        name,
        version,
        scalaVersion,
        sbtVersion,
        BuildInfoKey.action("buildTime") {
          // TODO: would really like to see nscala-time here for proper ISO-8601
          // new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new java.util.Date())
          DateTime.now
        },
        BuildInfoKey.action("buildUser") { sys.props.getOrElse("user.name", "unknown") }),
      buildInfoPackage := "com.htc.cs.dm2",

      scalacOptions ++= Seq("-feature"))

}

How do I get this to compile?  Am I in the right forum or should I send this to the play-framework guys?

Mark Harrah

unread,
Jun 17, 2013, 6:37:32 PM6/17/13
to simple-b...@googlegroups.com
This means to make nscala-time a dependency of your project's code. It will be on the classpath for compiling and running sources in src/... To use a library in a build definition, such as in a task implementation, declare it in project/plugins.sbt:

libraryDependencies +=
"com.github.nscala-time" %% "nscala-time" % "0.4.2",

This puts it on the classpath and runtime for build definitions (and tasks).
Here (or StackOverflow, which seems to be higher traffic these days) works.

-Mark

Robert Kuhar

unread,
Jun 17, 2013, 7:48:44 PM6/17/13
to simple-b...@googlegroups.com
Thanks.  That worked really well.

Bob
Reply all
Reply to author
Forward
0 new messages