向Maven项目添加本地依赖项的最佳方法 [英] Best way to add local dependency to Maven project

查看:572
本文介绍了向Maven项目添加本地依赖项的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此有很多疑问,但答案似乎相互矛盾。所以我想问一下我的Maven版本(3.0.4)。

There are a lot of questions about this, but the answers seem to contradict each other. So I wanted to ask it for my version of Maven (3.0.4).

我有一个不属于任何maven存储库的JAR文件。这是当地的依赖。我知道有两种方法可以将它添加到我的Maven项目中。

I have a JAR file that's not part of any maven repository. It's a local dependency. I understand there are two ways to add it to my Maven project.


  1. 将其添加为依赖项并在<$中指定文件路径c $ c>< systemPath> 属性。 (无需其他工作。)

  2. 创建本地存储库< my-project> / repo 并在此存储库中安装JAR 。然后,在我的pom.xml文件中添加新的存储库并添加新的依赖项。

  1. Add it as a dependency and specify the file path in the <systemPath> property. (No other work needed.)
  2. Create a local repository <my-project>/repo and install the JAR in this repository. Then, add the new repository in my pom.xml file and add the new dependency.

我很好奇哪种方式更好的做法?我听说过一些关于< systemPath> 属性的负面信息,虽然这种方式看起来更快。

I'm curious which way is better practice? I've heard some negative things about the <systemPath> property, although that way looks faster.

推荐答案

答案是,这取决于......

The answer is, it depends...


  1. 如果你把它添加为一个系统依赖性可能会变得依赖于路径,这使得在其他开发人员之间共享变得更加困难。当然,您也可以通过SCM分发相对于POM的第三方jar,但 systemPath 的意图更多是针对JDK或VM提供的依赖关系。来自有关 systemPath的文档

  1. If you add it as a system dependency it is likely to become path dependent which makes it more difficult to share among other developers. Sure you can also distribute the 3rd party jar relative to your POM via your SCM but the intention of systemPath is more for dependencies that are provided by the JDK or the VM. From the docs about systemPath:


它们通常用于告诉Maven有关JDK或VM提供的依赖项。因此,系统依赖性对于解决现在由JDK提供的工件的依赖性特别有用,但是可以在之前单独下载。

They are usually used to tell Maven about dependencies which are provided by the JDK or the VM. Thus, system dependencies are especially useful for resolving dependencies on artifacts which are now provided by the JDK, but where available as separate downloads earlier.


  • 在本地仓库中安装jar也不适合共享。它要求所有开发人员在构建之前将jar上传到他们的本地仓库。您当然可以添加一个脚本来处理这个问题,但总是很容易忘记上传和IMO更好的解决方案是下面的第3点。本地安装过程是此处描述的

    如果您在开发人员共享POM的组织中工作,则应将第三方jar上传到本地存储库管理器。这样你就可以轻松使用第三方jar,就像使用任何其他maven启用的jar一样。有关存储库管理员的完整列表,请查看此链接

    If you are working in an organization where the developers share the POM you should upload the 3rd party jar to a local repository manager. That way you can easily work with the 3rd party jar as if using any other maven enabled jar. Check this link for a comprehensive list on repository managers.

    总而言之,如果您与其他人共享POM,我建议您将其上传到本地存储库管理器。否则第二个选项可以为您服务。作为最后一个选项,我会回到选项编号1。

    To summarize, if you are sharing the POM with others I would suggest that you upload it to a local repository manager. Otherwise the second option can work for you. As a last option, I would fall back to option number 1.

    另请注意,这与您正在运行的Maven版本无关。

    Also note that this has nothing to do with which version of Maven you are running.

    这篇关于向Maven项目添加本地依赖项的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆