Hacker News new | ask | show | jobs
by delluminatus 4634 days ago
NPM stores dependencies in a node_modules folder within the project directory, i.e. "locally." It does have a command-line flag to store something globally, though -- useful for dependencies with executables.

I'm not a Java developer but it sounds like Maven stores all its dependencies globally (like in /usr/share/java). I'm not sure why that would be a "pain point" except making it hard to do different versions of the same library.

3 comments

Maven stores dependencies in ~/.m2/repository (so "globally" per user). However, it can and does store parallel versions of the same library without issue. It's not much of an issue unless you need to copy your source folder elsewhere, in which case you either need to copy your .m2 (with stuff from all your various projects) or wait until maven re-downloads everything.
Except that you request the dependency version you need for each module. Since the classloader can't load different versions of a dependency, it makes sense to unify the version across the application, and that is easily done with a Parent POM. If you are using OSGI to keep modules isolated when the classloader loads them, then you can request whatever version you want for a particular module.
The local repository cache is in ~/.m2/repository and each artifact is versioned, so you would have

  ~/.m2/repository/com/foo/bar/1.0/bar.jar

  ~/.m2/repository/com/foo/bar/1.1/bar.jar
etc., which prevents you from pulling in version 1.0 when you intend 1.1.