Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working offline with SBT and SNAPSHOT dependencies

Tags:

I have never been able to work offline with SBT on any of my projects. Now I'm in the middle of a move and my wardrobe-server hosting nexus is offline.

So running say:

sbt "set offline := true" run

I get among other missing deps:

[error] unresolved dependency: se.hedefalk#lift-utils_3.0_2.10;0.2-SNAPSHOT: not found

for the dependency declared as:

"se.hedefalk"       %% ("lift-utils_"+liftEdition) % ("0.2-SNAPSHOT"),

But I do have the dependency in my ivy cache:

$ ll ~/.ivy2/cache/se.hedefalk/lift-utils_3.0_2.10/
total 32
drwxr-xr-x  8 viktor  staff   272B Mar 14 11:36 ./
drwxr-xr-x  5 viktor  staff   170B Mar  8 10:38 ../
drwxr-xr-x  3 viktor  staff   102B Mar 14 11:36 docs/
-rw-r--r--  1 viktor  staff   4.5K Mar  4 15:54 ivy-0.2-SNAPSHOT.xml
-rw-r--r--  1 viktor  staff   4.0K Mar  4 15:54 ivy-0.2-SNAPSHOT.xml.original
-rw-r--r--  1 viktor  staff   1.8K Mar 14 11:36 ivydata-0.2-SNAPSHOT.properties
drwxr-xr-x  3 viktor  staff   102B Mar  8 10:38 jars/
drwxr-xr-x  3 viktor  staff   102B Mar 14 11:36 srcs/

Shouldn't that be enough? That whole set "offline := true" has never ever made any difference for me. The dependency resolution seems to happen before.

I really need to get this working now. I have had problems with this for years, but now I'm in the situation where I simply cannot work at all.

Over here: http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Dependency-Management-Flow.html

I read

When offline := true, remote SNAPSHOTs will not be updated by a resolution, even an explicitly requested update. This should effectively support working without a connection to remote repositories. Reproducible examples demonstrating otherwise are appreciated. Obviously, update must have successfully run before going offline.

I probably don't understand this correctly, but is it saying I shouldn't have the problem I have?

I have the same problem using:

> sbt "skip in update := true" run

Using sbt 0.13.5

Edit:

After having my repo online again, resolving all deps and then just setting my wifi to offline I can exit sbt and then run it. However, just running ;reload ;clean ;compile and I'm f***ed again. And If I exit I'm not even able to start sbt at all. Dependency resolution for the project happens before I can for instance try to analyse the dependency graph with dependency-tree or similar. This is highly irritating even if not online if say, trying to understand where a failing transitive dependency comes from.

like image 997
Viktor Hedefalk Avatar asked Jun 24 '14 20:06

Viktor Hedefalk


People also ask

Which is the correct way to add dependencies in SBT file?

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

How do we specify library dependencies in SBT?

You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

Where are SBT dependencies stored?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

What is SBT dependency management?

Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.


2 Answers

This seems like a terrible hack, but you can specify your ivy cache as an ivy repository, so that once your dependencies are downloaded, they can be resolved from the cache.

For example, your ~/.sbt/repositories could look like this:

[repositories]
  local
  maven-central
  cache: file://${user.home}/.ivy2/cache, [organisation]/[module]/ivy-[revision].xml, [organisation]/[module]/[type]s/[module]-[revision].[type]

Note: I had to set the ivy and artifact patterns explicitly. Add the local cache below any other repos so they get tried first.

like image 69
Justin Kaeser Avatar answered Oct 14 '22 23:10

Justin Kaeser


Me neither can use it in a one-liner.

But if I start sbt and then in sbt I use set offline := true it's working well.

like image 41
Varon Avatar answered Oct 14 '22 22:10

Varon