When bnd doesn't understand your dependencies

In most cases, bnd is an understanding and committed abstract model. I find that most bnd users just assume they can depend on bnd. And for normal projects, this is justified since it looks at the -buildpath and -testpath and some other instructions.

However, sometimes bnd fails to see your needs. For example, I had a project where I used the -export instruction to create an executable JAR. Such an executable JAR is defined in a bndrun file and bnd ignores those. So if you have any dependencies there, and the -runbundles is a big one, than bnd will miss them. This means the -export will be executed before all your dependencies are build. This can be tricky to spot because in Eclipse it tends to work but it fails on the CI because there we start from scratch.

The solution is the -dependson instruction. This will tell bnd explicitly that there is more to a build.

-dependson com.example.foo, com.example.bar

The instruction takes a SELECTOR. A selector filters a scope. In the case of the -dependson instruction, the scope are all the projects in the current workspace. To prevent cycles, bnd will remove the current project. Sometimes, like the export example, or the integration test, you really want to be the last. You can do this with a wildcard.

-dependson *

It should be clear that only one project can be the last. You will get a cycle error when you try to do this on multiple projects. Since this is a SELECTOR you can exclude projects. For example, if you have project a, b, and c. You want to build c last and b semi last.

c/bnd.bnd:
    -dependson *

b/bnd.bnd:
    -dependson !c,*