# Conditional package dependency to avoid build errors

**URL:** <https://discourse.julialang.org/t/conditional-package-dependency-to-avoid-build-errors/42742>\
**Category:** General Usage\
**Created:** [July 8, 2020, 4:01pm UTC](https://discourse.julialang.org/t/conditional-package-dependency-to-avoid-build-errors/42742 "2020-07-08T16:01:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)\
**Post date:** [July 8, 2020, 4:01pm UTC](https://discourse.julialang.org/t/conditional-package-dependency-to-avoid-build-errors/42742/1 "2020-07-08T16:01:28Z")

</div>

I’ve created a package called [anyMOD.jl](https://github.com/leonardgoeke/anyMOD.jl) that uses the Gurobi package as a dependency. However, Gurobi is only required for one special but quite useful feature and apart from that not used anywhere in the package. Building the Gurobi package successfully requires to have installed some additional software. This also prevents a package with a Gurobi dependency from being tested via Travis. As a result, I want Gurobi only to be a dependency, if some specific files exists in a specific directory.

Is there any way to achieve such a condition on package dependency? I looked into Requires.jl, but only found a way to make parts of the module dependant on dependencies.

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [July 8, 2020, 4:30pm UTC](https://discourse.julialang.org/t/conditional-package-dependency-to-avoid-build-errors/42742/2 "2020-07-08T16:30:05Z")

</div>

Usually you put the special feature that depends on `Gurobi` in some file `filerequiringgurobi.l` in `anyMod.jl` and load this using `Requires.jl` as follows:

```julia
function __init__ ()
    @require Gurobi="uuid of Gurobi" include("filerequiringgurobi.jl")
end

```

Then once one does `using Gurobi` (which implies hopefully a proper installation of Gurobi and the additional software), then the additional feature is loaded.

Probably I misunderstood the question, but isn’t this what you want?

---

<div class="post-metadata">

**Author:** ![lgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lgo/32/48751_2.png) [@lgo](https://discourse.julialang.org/u/lgo)\
**Post date:** [July 8, 2020, 5:19pm UTC](https://discourse.julialang.org/t/conditional-package-dependency-to-avoid-build-errors/42742/3 "2020-07-08T17:19:44Z")

</div>

Thanks. That actually worked. I misunderstood how the package actually works before.
