11# Locking Your Dependencies
22
33In the default use-case Dune will automatically determine which packages to
4- install, including solving compatible versions and installing their
5- dependencies recursively .
4+ install, by reading the package constrains, determining compatible versions and
5+ installing the dependencies automatically .
66
77For many projects this is a good and acceptable behavior as users often want to
88use new versions of their dependencies. However some projects might want to
9- keep a fixed set of dependencies that is only updated manually. This can be
10- done in multiple ways.
9+ keep a fixed set of (transitive) dependencies that is only updated manually.
1110
1211## Create a lock directory manually
1312
@@ -25,40 +24,21 @@ Solution for dune.lock:
2524```
2625
2726Whenever Dune encounters a ` dune.lock ` folder, it will use the set of
28- dependencies defined in the lock. The lock will not be updated until a user
29- creates a new lock by running ` dune pkg lock ` again.
27+ dependencies defined in the lock. It contains all the metadata about package
28+ names and versions, their dependencies & source locations that are necesary to
29+ build the projects dependencies.
3030
31- On the next build, Dune will read the solution from the ` dune.lock ` directory,
32- download and build the dependencies and then continue on building the project
33- as usual.
31+ On the next build, Dune will read the stored solver solution from the
32+ ` dune.lock ` directory, download and build the dependencies and then continue on
33+ building the project as usual.
34+
35+ The lock directory will not be updated until a new lock directory is created,
36+ by rerunning ` dune pkg lock ` .
3437
3538:::{note}
3639This approach is similar to using ` opam switch export --full --freeze ` to
3740export the configuration of a switch.
3841:::
3942
40- ## Pin the package repositories to a commit
41-
42- A way to ensure that dependencies won't change due to package updates is to pin
43- the package repositories to a fixed commit.
44-
45- ::::
46-
47- ::::{dropdown} ` dune-workspace `
48- :icon: file-code
49-
50- :::{literalinclude} locking/dune-workspace
51- :language: dune
52- :::
53-
54-
55- ::::
56-
57- On the next build, Dune will check out out these specific two repositories at
58- the specified commit and use them for resolving all dependencies. It will then
59- download and build the dependencies as usual.
60-
61- :::{note}
62- This approach is similar to pinning OPAM repositories by explicitely setting
63- them to known versions using commands like ` opam repository add <name> <fixed-url> ` .
64- :::
43+ Deleting the lock directory switches Dune back into automatically determining
44+ dependency versions via the declared package constraints.
0 commit comments