Repositories and Dependencies

Repositories and Dependencies


Any sufficiently interesting project
is going to depend on perhaps quite large collection of libraries. Maybe you start depending on just one or
two libraries, so you just put their JARs in your project
directory and keep on trucking. You end up having a huge
collection of JAR archives. But then, what if a new version
of your dependency is released? You’ll have to manually download and
update the JARs and in turn all of its dependencies and all of its
dependencies’ dependencies and so on. This is clearly getting unmanageable. Another option would be to include a
list of your project’s dependencies and have anyone who wants to build your
project go and download them all. Of course, they would then have to hunt
all over the internet to find them and they would have to check all the time to
make sure that the versions they have Natural list of your dependencies. Brutal, right? Of course, since this is a course about
Gradle, Gradle provides a better way. Most libraries, or more generally
artifacts, that you might want to use in your project are present in various
repositories around the internet. Most prominent repositories are probably
made in Central and jcenter. Anyone can upload artifacts
to these repositories, as long as they include
the appropriate meta data. Every artifact in the repository
can be identified and retrieved by a unique
set of coordinates. If an artifact has dependencies of
its own, that is also specified. The upshot is, Gradle knows how to retrieve artifacts
from all sorts of repositories and will store them in local cache to
make them available for your project. Not only that, but if you have multiple
projects using the same artifact, it will only ever be downloaded once. Gradle will also take care of retrieving
any transitive dependencies and will even resolve conflicts when
different parts of your dependency tree rely on different versions
of the same artifact.

Daniel Ostrander

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *