Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: advantages of dependency management

Tags:

java

maven

Which are the main advantages of Maven dependencies management? We have a versioned lib folder on the server and each developer just needs to import that directory in the IDE and keep it up to date. Could Maven be simpler than that?

like image 324
argon argon Avatar asked Jun 21 '13 07:06

argon argon


4 Answers

Using a per-project lib seems like a simple solution and it is. But eventually you will run into problems:

  • How do you remember where you got foo.jar from?
  • Are you sure it was a legit source that no hacker tampered with?
  • Which version is foo.jar exactly? Is it the original version or something that you patched?
  • You want JavaDoc/sources with that?
  • foo.jar needs a.jar which needs y.jar which needs z.jar needs ... You really want to download all that and manage it individually?
  • You start a second project. Now you have two lib folders. Do you copy the jars or do you reference them from the first project?
  • Your second project needs a different version of one JAR. How do you handle this?
  • Imagine you want to upgrade foo.jar to the next version. With Maven, this is a one-minute task. With a lib folder, it means: Searching the web, downloading the JAR, putting it in the right place, possible renaming it, deleting the old version, adding the new version, committing the change, cursing, doing the same for all dependencies, ...
  • You want to share your project with someone else. They might not want your versions of the JARs - Maven has a simple and efficient mechanism to override dependencies.
  • Eventually, your legal department will come to ask you to guarantee that your project is clean of incompatible licenses. Maven can give you a report of all licenses of all your dependencies.
like image 128
Aaron Digulla Avatar answered Sep 24 '22 02:09

Aaron Digulla


With maven you can have a private repository, or use public ones (like maven2) to obtain the libraries you use in your project, so you don't have to download them personally and manage them between your coworkers with your subversion server.

If you want to change one library for another one, or update it to a newer version you only have to modify the version number or the library name in your maven configuration file and it will be done, without care about where can you download the library from, and without having to share it with everyone. You will only have to share your pom.xml file.

Maven doesn't only give you this, you can configurate how to package the application (WAR, EAR, JAR, APK, etc.), compile it (JDK version, parameters, etc.) and even how to create the Eclipse structure of your project, so you can create a new project having only your sources, resources and the magic "pom.xml" maven configuration file.

You should give it a try!

like image 22
maqjav Avatar answered Sep 23 '22 02:09

maqjav


Yes it can!

"each developer just need to import that dir in the ide and keep it up to date"

Maven does this automagically ;-)

Also it has big advantages if you use continous integration and other deployment mechanisms. You can easilly build your project in any environment without caring about some lib folders. Additially there are a lot of plugins regarding building, deployment, code analasys and many more.

like image 28
André Stannek Avatar answered Sep 23 '22 02:09

André Stannek


Of course Maven is great, but there are also times when a versioned lib folder like yours can at least appear to be simpler. When you use libraries that don't have maven metadata, then you need to do some work before you can put it in your Maven Repo (you probably should still have one central repo on some server where you put such things).

like image 45
kutschkem Avatar answered Sep 22 '22 02:09

kutschkem