How to specify a repository for a dependency in Maven

dependenciesmaven-2

In projects with several dependencies and repositories, the try-and-error approach of Maven for downloading dependencies is a bit cumbersome and slow, so I was wondering if there is any way to set an specific repo for some declared dependencies.

For example, I want for bouncycastle to check directly BouncyCastle's Maven repo at http://repo2.maven.org/maven2/org/bouncycastle/ instead of official Maven.

Best Answer

Not possible. Maven checks the repositories in their declaration order until a given artifact gets resolved (or not).

Some repository manager can do something approaching this though. For example, Nexus has a routes feature that does something equivalent.