Search code examples
javaspringmaven

what is .m2 folder, how can I configure it if I have two repos with two different projects


I am using Maven for my project, but I have two projects with different set of dependencies. One project requires a ton of dependencies while the other requires only a few. So, when I do a Maven build all the unnecessary dependencies are also downloaded because the settings.xml is pointing to the same repository every time.

How do I let the Maven know to use a different repo?


Solution

  • .m2 folder is the default folder used by maven to store its:

    • settings.xml file which specifies properties, like the central repository to download your dependencies, the location of the so-called localRepository
    • by default, the localRepository in which maven stores all the dependencies your project might need to run.

    Basically, when you build a Java application, the JDK only is not enough. You might need 3rd part libraries to help during the development. For instance:

    • A lib to read CSV file
    • A lib to do unit tests
    • A lib to indicate weather ?

    Anyway, without Maven, you'd be forced to download everything onto your computer, and indicate manually to your Java apps where to find those dependencies. That is the role of maven. It is a dependency management tool, that centralize in a single place the dependencies your project has, and give you in a standard way access to those librairies, in order to make you more efficient.

    By default, maven fetches the dependencies from this website: https://repo1.maven.org/maven2/.

    In term of efficiency, it is better to share the same localRepository across your projects, as it avoids maven from downloading the same dependencies again... I don't even know if there is a way, and if not, that is for a good reason: It is useless to have different local Repository in your computer