Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Maven: where do dependencies and libraries installed locally up?

Tags:

java

maven

I'm building a Java project that has a dependency on a library. mvn.bat clean install produced the target subdirectories as expected, and the project built fine with mvn.bat clean install as well.

What's not expected is that when I deleted the entire directory of the library, the outer project still built fine, although the library it depends on was gone.

How does this work?

UPDATE: Turns out Maven makes some sort of cache in %USERPROFILE\.m2.

like image 864
Dan Dascalescu Avatar asked Sep 19 '25 01:09

Dan Dascalescu


2 Answers

You are most likely thinking of your local repository where everything you install locally (and maven downloads for you from the central repository) is put for later usage.

The behavior you describe is intentional, and allows for building A once and then let B reference it whenever needed, without having to recompile A every time. This is usually very desirable, especially in teams or with large code bases.

Note, that for changing code you should be using -SNAPSHOT artifacts. They are treated slightly differently.

like image 163
Thorbjørn Ravn Andersen Avatar answered Sep 20 '25 14:09

Thorbjørn Ravn Andersen


Your dependencies are always downloaded into .m2/repository.

If you want to have some predictability on downloaded libraries in your team, you can put in place a repository manager like Nexus : https://repository.apache.org/index.html#welcome

Instead of downloading dependencies from Maven central, your developers will download their dependencies from this repository manager.

like image 41
user2147970 Avatar answered Sep 20 '25 13:09

user2147970