# Having local packages in a monorepo depend on one another

**URL:** <https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454>\
**Category:** Package Management\
**Tags:** question, package, pkg\
**Created:** [November 19, 2020, 6:34pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454 "2020-11-19T18:34:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Wheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_wheeler/32/16232_2.png) [@Tim\_Wheeler](https://discourse.julialang.org/u/Tim_Wheeler)\
**Post date:** [November 19, 2020, 6:34pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/1 "2020-11-19T18:34:57Z")

</div>

We’re using a monorepo to maintain our julia packages, with a directory structure along the lines of:

```julia
julia
    PackageOne
    PackageTwo
    PackageThree

```

I can add these packages to my top-level Project by running `Pkg.develop(path="<path_to_package>")` and can subsequently use each package.

I am having trouble having a package depend on another. I’ve tried various versions of Pkg.add, but they all seem to expect each package individually to be a git repo.

With, say, PackageThree activated, I’ve tried:

```julia
julia> Pkg.add("PackageOne")
   Updating registry at `~/.julia/registries/General`
   Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Resolving package versions...
ERROR: expected package `PackageOne [8b4b255c]` to be registered

```

```julia
julia> Pkg.add(path ="<path_to_package_one>")
ERROR: Did not find a git repository at `<path_to_package_one>`

```

Seeing that I can develop packages at paths, is there a way to also depend on other packages at paths?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 19, 2020, 7:55pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/2 "2020-11-19T19:55:38Z")

</div>

> [@Tim\_Wheeler](#):
>
> I can add these packages to my top-level Project by running `Pkg.develop(path="<path_to_package>")` and can subsequently use each package.

This is what you want do do again for the local projects too.

---

<div class="post-metadata">

**Author:** ![Tim\_Wheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_wheeler/32/16232_2.png) [@Tim\_Wheeler](https://discourse.julialang.org/u/Tim_Wheeler)\
**Post date:** [November 19, 2020, 8:42pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/3 "2020-11-19T20:42:09Z")

</div>

Sorry, I think I am misunderstanding something. The packages are already in my Project.toml in .julia/environments/1.5.

Adding the package / developing when I check out my local package doesn’t work either (run from ~/myrepo/julia/):

```julia
(@v1.5) pkg> activate PackageThree
 Activating environment at `~/myrepo/julia/PackageThree/Project.toml`

julia> using Pkg

julia> Pkg.develop(path="PackageOne")
Path `PackageOne` exists and looks like the correct package. Using existing path.
  Resolving package versions...
No Changes to `~/myrepo/julia/PackageOne/Project.toml`
No Changes to `~/myrepo/julia/PackageOne/Manifest.toml`

julia> Pkg.add("PackageOne")
   Updating registry at `~/.julia/registries/General`
   Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Resolving package versions...
ERROR: expected package `PackageOne [8b4b255c]` to be registered

julia> Pkg.add(path="PackageOne")
ERROR: Did not find a git repository at `PackageOne`

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 19, 2020, 8:58pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/4 "2020-11-19T20:58:02Z")

</div>

Just like you did `Pkg.develop` to add the packages to your global environment (`~/.julia/environments/1.5`) you should use `Pkg.develop` when you add them as dependencies of each other. Here is an example:

Generate two local packages:

```shell
$ jlpkg generate A; jlpkg generate B
 Generating project A ...
 Generating project B ...

```

Add them with `develop` and the path:

```shell
$ jlpkg --project=. dev A B # Add both to "global env"
  Resolving package versions...
Updating `/tmp/Project.toml`
  [a8860211] + A v0.1.0 `A`
  [c725e7a7] + B v0.1.0 `B`
Updating `/tmp/Manifest.toml`
  [a8860211] + A v0.1.0 `A`
  [c725e7a7] + B v0.1.0 `B`

```

Manifest looks good:

```shell
$ cat Manifest.toml 
# This file is machine-generated - editing it directly is not advised

[[A]]
path = "A"
uuid = "a8860211-dfc0-462f-9fbf-c3432d7e395f"
version = "0.1.0"

[[B]]
path = "B"
uuid = "c725e7a7-9ad5-4b2e-b018-0ca07287f03e"
version = "0.1.0"

```

Add `B` as a dependency to the `A` project:

```shell
$ jlpkg --project=A dev B # Add B as a dependency to A
  Resolving package versions...
Updating `/tmp/A/Project.toml`
  [c725e7a7] + B v0.1.0 `../B`
Updating `/tmp/A/Manifest.toml`
  [c725e7a7] + B v0.1.0 `../B`

```

Sync the global manifest to update `A`’s dependencies

```shell
$ jlpkg --project=. resolve # Sync the global manifest
[...]

```

Make sure `A` properly depends on `B`:

```shell
$ cat Manifest.toml 
# This file is machine-generated - editing it directly is not advised

[[A]]
deps = ["B"]
path = "A"
uuid = "a8860211-dfc0-462f-9fbf-c3432d7e395f"
version = "0.1.0"

[[B]]
path = "B"
uuid = "c725e7a7-9ad5-4b2e-b018-0ca07287f03e"
version = "0.1.0"

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 19, 2020, 9:31pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/5 "2020-11-19T21:31:01Z")

</div>

> [@Tim\_Wheeler](#):
>
> ```julia
> julia> Pkg.add(path ="<path_to_package_one>")
> ERROR: Did not find a git repository at `<path_to_package_one>`
> 
> ```
> 
> Seeing that I can develop packages at paths, is there a way to also depend on other packages at paths?

`add` is not the right tool in this scenario, but if it were the incantation would be `Pkg.add(path=<path_to_julia>, subdir="PackageOne")`.

Myself I would just make a registry and register the packages, then go on as usual and not worry about relative paths and stuff.

---

<div class="post-metadata">

**Author:** ![Tim\_Wheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_wheeler/32/16232_2.png) [@Tim\_Wheeler](https://discourse.julialang.org/u/Tim_Wheeler)\
**Post date:** [November 19, 2020, 9:58pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/6 "2020-11-19T21:58:20Z")

</div>

Registries seem to have to be repos too:

```julia
(@v1.5) pkg> registry add .
    Copying registry from `~/myrepo/julia/MyRegistry`
ERROR: no `repo` entry in `Registry.toml`.

```

I took a look at [7. Registries · Pkg.jl](https://julialang.github.io/Pkg.jl/v1/registries/) but it only adds via url.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 19, 2020, 10:17pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/7 "2020-11-19T22:17:19Z")

</div>

I don’t think its necessary to use a registry for this. The previous advice about adding the packages one by one is best.

---

<div class="post-metadata">

**Author:** ![Tim\_Wheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_wheeler/32/16232_2.png) [@Tim\_Wheeler](https://discourse.julialang.org/u/Tim_Wheeler)\
**Post date:** [November 19, 2020, 10:35pm UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/8 "2020-11-19T22:35:54Z")

</div>

Aha! What I was missing is that calling `Pkg.develop(path="julia/PackageOne")` once PackageThree is activated adds it to the Project.toml, so `Pkg.add` is not needed. Thank you.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 20, 2020, 12:07am UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/9 "2020-11-20T00:07:51Z")

</div>

Agree, the monorepo approach seems at odds with using a registry: if all the packages are in a single repo and they get updated in lockstep, what is the purpose of a registry?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 20, 2020, 7:34am UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/10 "2020-11-20T07:34:39Z")

</div>

> [@Tim\_Wheeler](#):
>
> Registries seem to have to be repos too:
> 
> ```julia
> (@v1.5) pkg> registry add .
> Copying registry from `~/myrepo/julia/MyRegistry`
> ERROR: no `repo` entry in `Registry.toml`.
> 
> ```

Not really. That error message only says that `Registry.toml` must contain a `repo` field, not that it’s actually going to do anything with it. Although it certainly would be most convenient and idiomatic to have the registry in a separate repository, the rest of Pkg, outside of `repository add`, wouldn’t know or care where a repository came from, say a symbolic link from `~/.registries/MyRegistry` to `<path to monorepo>/MyRegistry`.

> [@StefanKarpinski](#):
>
> Agree, the monorepo approach seems at odds with using a registry: if all the packages are in a single repo and they get updated in lockstep, what is the purpose of a registry?

It depends on how the packages are actually used or deployed but primarily it gives you the _option_ of falling out of lockstep and allows you to use Pkg in a standard way.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 20, 2020, 8:17am UTC](https://discourse.julialang.org/t/having-local-packages-in-a-monorepo-depend-on-one-another/50454/11 "2020-11-20T08:17:05Z")

</div>

> [@Tim\_Wheeler](#):
>
> Registries seem to have to be repos too:

They don’t, we should just remove the check that this field exists, imo.
