I wanted to specify the versions of my dependencies in my dune-project
file explicitly, to avoid any breakages due to newer versions (in the same way I might list Java dependencies in a Gradle build file, if that means anything to you).
The documentation for Dune suggests you can declare dependencies by using (depends ...)
under (package ...)
.
In my dune-project
, I have
(package
(name my_app)
(synopsis "A short synopsis")
(description "A longer description")
(depends
(ocaml (= "5.0.0"))
dune)
(tags
(topics "to describe" your project)))
Note here that I've listed "5.0.0" as the version of OCaml. On my system, I only have 4.14.1. When I run dune build
, my program compiles, all the tests pass and the program runs.
The documentation doesn't really explain what depends
is intended for. I had expected an error or something else to happen (like it would download the upgraded version, like how Gradle would work).
Could someone enlighten me please?
The depends
field only matters at the package level.
Packages are published bundle of libraries or executables.
Consequently, the failure that you expect will only happen when trying to install the package (for instance with opam pin add .
).