User Stories: Offline mode and Dependency Locking
Currently, sbt has a broken notion of offline := true
setting which does not ensure going offline works. A big part of this are the technical issues surrounding our usage of Ivy, and preventing it from attempting to hit the internet. However, let's outline what the story in sbt should be.
If the user has offline := true
specified in their build, then sbt should NOT attempt to hit the internet (or possibly use ivy at all) to resolve dependencies. When the user runs the update task:
- sbt checks to see if the necessary, already resolved, JAR files exist.
- If they do not, sbt issues a warning stating which files are missing, and asking the user to return to online mode.
- If they do exist, sbt continues without touching the internet (at least via the update task).
This is the new meaning for the offline
flag and reflects only that tasks should NOT attempt to hit the inter/intra-net and instead issue errors if local caches are not available.
When the user runs ivy resolution, sbt generates a cache of the resolution and does not re-run ivy until one of the inputs has changed. Additionally, the user may opt-in to store this cache file in a human-readable format within the local project's source directory. For example, a build.sbt with the following:
dependencyCacheFile := baseDirectory.value / "dependencies"
dependencyCacheFileFormat := DependencyCacheFileFormat.Text
will lead to the creation of a dependencies
file in the root of that project which is both human readable, AND something which could be checked into the SCM. The format of the lockfile should be friendly for human-merge-conflicts, and more importantly, if it's out of data, running sbt update should regenerate it.
TODO - define the human readable, merge friendly format, although merging isn't as much of an issue since it'll be regenerated if out of date.
Possible example:
[dependencies]
org.scala-lang#scala-library#2.10.2, <cache>/org.scala-lang/scala-library/jars/scala-library-2.10.2.jar
[evictions]
org.scala-lang#scala-library#2.10.1
[inputs]
???
When a user wishes to ensure that they can work on a project offline, they can run a goOffline
command. This command is responsible for:
- Running update tasks on projects, ensuring a valid dependency cache file exists
- Setting
offline := true
in all subprojects so that only the dependency cache file is used when resolving dependencies.
When a user wishes to go back to online mode, they can run a goOnline
command which will:
- Set
offline := false
in all subprojects so that dependency cache files will be updated.