What are Dependency Managers?
What on earth is composer, npm, gradle, maven? Why must I use dependency managers?
Why this Write-up
This write-up is for beginner devs. I interact with them often and write about questions they ask me so others can benefit.
First what is a dependency? A Dependency is an external standalone program module (library) that can be as small as a single file or as large as a collection of files and folders organized into packages that performs a specific task. For example, backup-mongodb is a dependency for a blog application that uses it for remotely backing up its database and sending it to an email address. In other words, the blog application is dependent on the package for doing backups of its database.
Dependency managers are software modules that coordinate the integration of external libraries or packages into larger application stack. Dependency managers use configuration files like composer.json, package.json, build.gradle or pom.xml to determine:
- What dependency to get
- What version of the dependency in particular and
- Which repository to get them from.
A repository is a source where the declared dependencies can be fetched from using the the name and version of that dependency. Most dependency managers have dedicated repositories where they fetch the declared dependencies from. For example, maven central for maven and gradle, npm for npm, and packagist for composer.
So when you declare a dependency in your config file — e.g. composer.json, the manager will goto the repository to fetch the dependency that match the exact criteria you have set in the config file and make it available in your execution environment for use.
Example of Dependency Managers
- Composer (used with php projects)
- Gradle (used with Java projects including android apps. and also is a build tool)
- Node Package Manager (NPM: used with Nodejs projects)
- Maven (used with Java projects including android apps. and also is a build tool)
- and so on.
Why do I need Dependency Managers
Summing them up in two points:
- They make sure the same version of dependencies you used in dev environment is what is being used in production. No unexpected behaviours
- They make keeping your dependencies updated with latest patch, release or major version very easy.
You can add to the list as you get to find out more while using them or let me know about them in the response section.
Thanks for reading and please remember to recommend it for others that might need it also by clicking the heart icon below
So, Prodsters Learning is running an online training for web and mobile development. Yes I know you can learn yourself, but you learn faster with mentorship and guidance especially when you are learning with model projects. Check it out now