dub.selections.json & optional dependencies: How's it work?

jmh530 john.michael.hall at gmail.com
Fri Feb 24 20:12:28 UTC 2023

On Friday, 24 February 2023 at 19:37:41 UTC, Steven Schveighoffer 
> On 2/24/23 2:01 PM, jmh530 wrote:
>> I'm looking at the dub package format [1] about optional 
>> dependencies and it says:
>> "With this set to true, the dependency will only be used if 
>> explicitly selected in dub.selections.json. If omitted, this 
>> attribute defaults to false."
>> And it occurs to me that I don't know anything about how 
>> dub.selections.json works.
> Let's say you have dependency A, which has an *optional* 
> dependency on B.
> In your project, if you depend on A, but don't explicitly 
> depend on B, then A will be built without B as a dependency.
> If you have a dependency on A *and* B, then B's optional 
> dependency will kick in, and participate in the selection of 
> it's version.
> So for instance, you could depend on B version 1 or higher, and 
> the optional dependency could be on v1.5 or higher, it will 
> select the highest version of 1.5
> dub.selections.json only applies to the primary project. So the 
> decision on which versions of which dependencies to use is 
> decided by the whole tree.
> -Steve

Ok this makes sense. So it's all about dependencies downstream. 
For instance, if I list B as a dependency in my project but never 
use it in my own project, it will still compile in (so for 
instance if A's functionality differs depending on if B is 
included, then I will get that functionality even if I don't use 
B directly in my project).

More information about the Digitalmars-d-learn mailing list