Search code examples
scalasbtcurly-braces

object time is not a member of package org.joda


I am learning scala follow this tutorial with docker image hseeberger/scala-sbt

with first version of build.sbt

libraryDependencies += "joda-time" % "joda-time" % "2.10.2"

everything is OK.

this piece of code (snippet_1)

import org.joda.time._
var dt = new DateTime

got what I want.

with second version of build.sbt

libraryDependencies ++= Seq{
    "joda-time" % "joda-time" % "2.10.2";
    "org.joda" % "joda-convert" % "2.2.1"
}

snippet_1 got this error

<console>:7: error: object time is not a member of package org.joda
       import org.joda.time._
                       ^

the only difference from that tutorial is that I replaced , with ; in the build.sbt as , causes error.

this command comes from this post

sbt eclipse

causes this error

[warn] Executing in batch mode.
[warn]   For better performance, hit [ENTER] to switch to interactive mode, or
[warn]   consider launching sbt without any commands, or explicitly passing 'shell'
[info] Loading project definition from /root/project
[info] Set current project to root (in build file:/root/)
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error]        ^

any ideas?


Solution

  • The problem is this:

    Seq{
        "joda-time" % "joda-time" % "2.10.2";
        "org.joda" % "joda-convert" % "2.2.1"
    }
    

    Curly brackets mean you're passing Seq a single argument in the form of a code block. The value of a code block is always the value of the last line in the block - in this case, "org.joda" % "joda-convert" % "2.2.1". The joda-time dependency is never added.

    You can fix this by using round brackets and commas to supply multiple arguments to Seq:

    Seq(
        "joda-time" % "joda-time" % "2.10.2", 
        "org.joda" % "joda-convert" % "2.2.1"
    )
    

    Of particular note:

    the only difference from that tutorial is that I replaced , with ; in the build.sbt as , causes error.

    ; and , have entirely different meanings in Scala and are not interchangeable. If you find yourself needing to make that replacement, you should stop and check what you're doing.