3
votes

I'm trying to understand the use of SBT 0.13.1 offline. My goal is to bring whatever is necesary to an offline environment on a USB stick. I thought that if the ivy cache was copied then SBT could pull everything it needs out of it, but that doesn't seem to be the case.

For example...

I'll start by deleting the .ivy2 folder, just to be sure. Now, while online I use the following build.sbt and project/plugins.sbt files to create my eclipse project. from SBT 0.13.1

build.sbt:

name := "TestProject"

version := "0.0.1"

scalaVersion := "2.10.3"

libraryDependencies ++= Seq(
    "org.apache.commons" % "commons-math3" % "3.2",
    "ch.qos.logback" % "logback-classic" % "1.1.1"
)

project/plugins.sbt:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0")

Sill on the same computiner I go offline, and now sbt clean eclipse gives lots of unresolved dependency errors. E.g.

[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn]  module not found: org.scala-lang#scala-library;2.10.3
[warn] ==== local: tried
[warn]   /home/user/.ivy2/local/org.scala-lang/scala-library/2.10.3/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom
[info] Resolving ch.qos.logback#logback-classic;1.1.1 ...
[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn]  module not found: ch.qos.logback#logback-classic;1.1.1
[warn] ==== local: tried
[warn]   /home/user/.ivy2/local/ch.qos.logback/logback-classic/1.1.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
[info] Resolving org.scala-lang#scala-reflect;2.10.3 ...
[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.3/scala-reflect-2.10.3.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn]  module not found: org.scala-lang#scala-reflect;2.10.3
[warn] ==== local: tried
[warn]   /home/user/.ivy2/local/org.scala-lang/scala-reflect/2.10.3/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.3/scala-reflect-2.10.3.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scala-lang#scala-library;2.10.3: not found
[warn]  :: ch.qos.logback#logback-classic;1.1.1: not found
[warn]  :: org.scala-lang#scala-reflect;2.10.3: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

Is it really impossible to clean when working offline?

I notice that SBT is looking in .ivy2/local, but there is no such folder. Only '.ivy2/cache'.

Update:

Suggestion to add .ivy2/local didn't work. It gives many MalformedURLException

[warn]  :: org.scala-lang#scala-library;2.10.3: ivy2 cache: unable to get resource for org/scala-lang#scala-library;2.10.3: res=/home/user/.ivy2/cache/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom: java.net.MalformedURLException: no protocol: /home/user/.ivy2/cache/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom

It's looking for a directory org/scala-lang etc, but thr directories in cache are of the form org.scala-lang

Update 2

It seems that the problem is caused with some interaction with logback. I've created a clearer version of my question here, and am accepting the answer that indicated that this 'should' run out of the box.

2
have you tried to set offline := true? Also see Dependency Management4e6
Tried it, but no change. My understanding of offline := true was that it would stop SNAPSHOTs from constantly checking, but I'm not using any snapshots, directly at any rate.Pengin

2 Answers

1
votes

If you build the project online, then you can go offline after. Basically, you'd just want to copy the ~/.ivy2 folder (and possibly ~/.sbt folder - unsure) into your environment from a location that has done the building and dependency resolution before.

Removing target/ in a project, then going offline, I can see that this does cause the resources to be resolved.

[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 4 Scala sources to [...]
1
votes

I'm not sure this will work but I guess you need to add another resolver in your Build.scala (or build.sbt) like this:

resolvers += "ivy2 cache" at "/home/user/.ivy2/cache"

Let me know if this works, I'm also curious about it.

Edit:

I tried it and sbt does look in your ivy2 cache, go in your build.sbt and add this line:

resolvers += Resolver.file("ivy2 cache", file("/path/to/your/ivy2/cache/"))(Resolver.ivyStylePatterns)

Now SBT should be looking in that directory too.