# How to add a Directory Package to an existing Project?

**URL:** <https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [April 25, 2021, 6:18pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997 "2021-04-25T18:18:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aschweig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aschweig/32/23893_2.png) [@aschweig](https://discourse.julialang.org/u/aschweig)\
**Post date:** [April 25, 2021, 6:18pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/1 "2021-04-25T18:18:55Z")

</div>

I am trying to using Julia 1.6.1 for application development.  
I like to make a separation between “library code” and the main program.

In my mind, a directory layout close to the following might work:

- MyApp ← the project created with `generate MyApp`
  - Manifest.toml
  - Project.toml
  - src/
    - MyApp.jl ← module MyApp; include(“included.jl”);
    - MyApp ← runnable from bash, using MyApp; MyApp.main()
    - included.jl

  - Lib/
    - src/
      - Lib.jl ← No dependency on MyApp.jl

  - test/
    - runtests.jl
    - Manifest.toml
    - Project.toml

  - notebooks/

When I add `using Lib` to MyApp.jl, I get `Package MyApp does not have Lib in its dependencies`.

Doing `add Lib` results in:

```julia
(MyApp) pkg> add Lib
[ Info: Resolving package identifier `Lib` as a directory at `~/Projects/MyApp/Lib`.
ERROR: Did not find a git repository at `Lib`

```

Typically, edits are being made to MyApp.jl while Lib.jl changes slowly.  
The package `Lib` would only ever be used by MyApp.jl; it makes sense for Lib.jl and MyApp.jl to live in the same git repo.

Is there a canonical way to add a Directory Package to a Project?

---

<div class="post-metadata">

**Author:** ![aschweig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aschweig/32/23893_2.png) [@aschweig](https://discourse.julialang.org/u/aschweig)\
**Post date:** [April 26, 2021, 2:59am UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/2 "2021-04-26T02:59:25Z")

</div>

A bit more digging, I have found that I can use “dev” as mentioned in the reply linked here:  
[https://github.com/JuliaLang/Pkg.jl/issues/1251#issuecomment-647115302](https://github.com/JuliaLang/Pkg.jl/issues/1251#issuecomment-647115302)

Cloning ma-laforge’s PkgTestRoot.jl repo, I confirmed that I could allow sibling dependencies in subpkgs using “dev” instead of “add” –  
[https://github.com/ma-laforge/PkgTestRoot.jl](https://github.com/ma-laforge/PkgTestRoot.jl)

I would still like to know if this is a common approach.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 26, 2021, 11:33am UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/3 "2021-04-26T11:33:00Z")

</div>

> [@aschweig](#):
>
> I would still like to know if this is a common approach.

It is a reasonable solution for certain cases, I use it sometimes, especially if I want to distribute unregistered packages within a repo.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 26, 2021, 1:54pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/4 "2021-04-26T13:54:36Z")

</div>

> [@aschweig](#):
>
> Typically, edits are being made to MyApp.jl while Lib.jl changes slowly.  
> The package `Lib` would only ever be used by MyApp.jl; it makes sense for Lib.jl and MyApp.jl to live in the same git repo.

I’m not sure I understand why you don’t want the `MyApp` code and the `MyLib` code to live in the same project/package? (For example, the code defining `MyLib` could be put into some subdirectory of `src`, and maybe put in a separate submodule if you want to guarantee it doesn’t depend on outer `MyApp` code)

---

<div class="post-metadata">

**Author:** ![aschweig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aschweig/32/23893_2.png) [@aschweig](https://discourse.julialang.org/u/aschweig)\
**Post date:** [April 26, 2021, 2:59pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/5 "2021-04-26T14:59:56Z")

</div>

Thanks ffevotte,

> I’m not sure I understand why you don’t want the `MyApp` code and the `MyLib` code to live in the same project/package?

What I have done so far is to use `include("...")` to spread my code among many files. Perhaps because of my experience with C++ templates, I trend to view large include graphs as something to be wary of, particularly as the application grows larger. There seems to have been some lively discussion about [using relative imports](https://github.com/JuliaLang/julia/issues/4600) – but some proposals amount to something like `include` + `using` – which feels like it makes pre-compilation an impossibility. Is there a way to use submodules without using `include` or guarantee pre-compilation?

My understanding is that [pre-compilation occurs at the package level](https://discourse.julialang.org/t/organisation-into-submodules-and-multiple-dispatch/40641), hence the desire to factor out stable code into packages (using `using Lib` not `include`) keeping all within the same git repo for MyApp.

From what I have read, one package per project per repo is a valid way to factorize development of larger applications. But I haven’t warmed to this as it seems like overkill and increases coordination cost between components; for packages used in one code base, git branches suffice for my needs. There may be a way forward by manipulating `LOAD_PATH` outside of the Pkg REPL; if so I would like to hear if/how others do it in v1.6+.

---

<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:** [April 26, 2021, 3:05pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/6 "2021-04-26T15:05:03Z")

</div>

I’m not following the specifics of your problem exactly, but you should use `dev` instead of `LOAD_PATH` for sure.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 26, 2021, 3:25pm UTC](https://discourse.julialang.org/t/how-to-add-a-directory-package-to-an-existing-project/59997/7 "2021-04-26T15:25:10Z")

</div>

> [@aschweig](#):
>
> My understanding is that [pre-compilation occurs at the package level](https://discourse.julialang.org/t/organisation-into-submodules-and-multiple-dispatch/40641), hence the desire to factor out stable code into packages

Yes, if `Lib` has long precompilation times, it is a good reason to factor it out in a separate package, in order to ensure that it will be pre-compiled independently. (To be clear, if `Lib` was a submodule of `MyApp`, it would still get precompiled, but the precompilation would happen again each time `MyApp` changes).

  

> [@aschweig](#):
>
> There may be a way forward by manipulating `LOAD_PATH` outside of the Pkg REPL; if so I would like to hear if/how others do it in v1.6+.

Please don’t manipulate `LOAD_PATH` yourself, and use `Pkg.dev` instead (giving it a relative path to your library).

Note that if you want to get the full benefits of having `Lib` be a fully fledged package, it should have its own `Project.toml`, that list its own dependencies.
