什么是 .m2 文件夹,如果我有两个仓库和两个不同的项目,我该如何配置它

huangapple go评论112阅读模式
英文:

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

问题

我正在使用Maven来管理我的项目,但我有两个具有不同依赖关系集的项目。其中一个项目需要大量的依赖,而另一个项目只需要很少的依赖。因此,当我执行Maven构建时,所有不必要的依赖项也会被下载,这是因为settings.xml每次都指向同一个仓库。
我该如何让Maven知道使用不同的仓库呢?

英文:

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?

答案1

得分: 11

.m2文件夹是Maven的默认文件夹,用于存储:

  • settings.xml文件,其中指定属性,例如用于下载依赖项的中央仓库,所谓的localRepository的位置。
  • 默认情况下,localRepository是Maven存储项目可能需要运行的所有依赖项的位置。

基本上,在构建Java应用程序时,仅使用JDK是不够的。您可能需要第三方库来在开发过程中提供帮助。例如:

  • 用于读取CSV文件的库
  • 用于执行单元测试的库
  • 用于指示天气的库

无论如何,如果没有Maven,您将被迫将所有内容下载到计算机上,并手动指示您的Java应用程序在哪里找到这些依赖项。
这就是Maven的作用。它是一个依赖项管理工具,将项目的依赖项集中在一个地方,并以标准方式为您提供访问这些库的途径,从而提高效率。

默认情况下,Maven从此网站获取依赖项:https://repo1.maven.org/maven2/。

从效率的角度来看,最好在项目之间共享相同的localRepository,这样可以避免Maven再次下载相同的依赖项……我甚至不知道是否有一种方法,如果没有,那么这是有充分理由的:在计算机上拥有不同的本地仓库是没有意义的。

英文:

.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

huangapple
  • 本文由 发表于 2020年7月29日 00:15:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63138495.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定