2

I have an SBT project that depends on two snapshot dependencies. Every time I build it, it goes off to the remote repository to fetch the dependencies. This is true even if I set offline := true.

When I look at how it is trying to resolve the local dependencies, the build is saying it is looking in "local", i.e., ~/.ivy2/local/... -- which is a nonexistent directory.

The jars are in ~/.ivy2/cache/... and this is where SBT downloads them when it pulls the dependencies from the remote server.

I have searched my .sbt and .scala build files and the string "local" does not appear in them in connection with a repository or cache.

SBT is at version 0.13.11 building against scala 2.11.8.

Why is SBT doing this, and how can I get it to see the cached jars?

Diligent Key Presser
  • 4,183
  • 4
  • 26
  • 34
psfblair
  • 51
  • 4
  • The ~/.ivy2/local directory is the default local Ivy repository to which you can publish using publish-local. (See http://www.scala-sbt.org/0.12.4/docs/Detailed-Topics/Publishing.html .) So the issue is that SBT isn't looking at the local cache at all. – psfblair Sep 15 '16 at 16:18
  • More discussion of this issue here: http://stackoverflow.com/questions/24395307/working-offline-with-sbt-and-snapshot-dependencies – psfblair Sep 15 '16 at 19:11

2 Answers2

1

If you want to prevent SBT from trying to download from official repositories you could simply create a file project/offline-repositories:

[repositories]
  mirror-central: file:////nexus/central
  mirror-maven-central-org: file:////nexus/maven-central-org
  ...

(/nexus/central and /nexus/maven-central-org should contain a (partial) mirror of what you need offline)

Then call sbt with the sbt.repository.config property configured:

-Dsbt.override.build.repos=true \
-Dsbt.repository.config=./project/offline-repositories

For Reference:

EDIT

If you want to use your ~/.m2 cache:

[repositories]
  mirror-central: file:////home/XXXXX/.m2/repository
  mirror-maven-central-org: file:////home/XXXXX/.m2/repository
  ...
Community
  • 1
  • 1
Filippo Vitale
  • 7,597
  • 3
  • 58
  • 64
  • 1
    The problem was that it wasn't using the local ivy cache when the files were in the cache. Your suggestion is a workaround, but it doesn't really address the issue I raised. – psfblair Sep 15 '16 at 16:15
  • True, it is a workaround as I don't think it would be possible. Let's wait for more answers and if I am wrong I will remove this response. – Filippo Vitale Sep 15 '16 at 16:18
0

This apparently is because in my Ivy cache I had a file named ~/.ivy2/cache/com.xxx/xxx-utils/ivy-2.3.2-SNAPSHOT.xml.original , which the build was trying and failing to parse. I'm not sure where this file came from; conceivably it was put there manually ages ago.

psfblair
  • 51
  • 4
  • I seem to have been mistaken about this. I created a local Ivy repository and the build passed. I then tried removing the local Ivy repository under ~/.ivy2/local and my build worked -- but then I tried building a different project using the same snapshot jar and the build failed. When I put the local Ivy repository back the second build passed. – psfblair Sep 15 '16 at 16:27