Maven的:添加一个依赖由相对路径罐子 [英] Maven: add a dependency to a jar by relative path

查看:309
本文介绍了Maven的:添加一个依赖由相对路径罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个专有的罐子,我想添加到我的聚甲醛作为依赖。

但我不希望将其添加到存储库。原因是,我想我平时Maven的命令,如 MVN编译等,工作开箱。 (没有从开发商,要求一个以本身它添加到一些信息库)。

我想罐子是在源控制的3rdParty lib和pom.xml文件链接到它由相对路径。

可以这样做?怎么样?


解决方案

  

我想罐子是在源控制的3rdParty lib和pom.xml文件链接到它由相对路径。


如果你真的想这样(明白了,如果你不能使用公司资源库),那么我的建议是使用文件存储库本地的项目,并为不使用 系统范围依赖。在系统范围应尽量避免,这种依赖不会在很多情况下工作良好(例如,在组装),他们会大于收益更多的麻烦。

所以,相反,声明一个本地库到项目:

 <库>
  <&库GT;
    < ID>我本地的回购< / ID>
    < URL>文件:// $ {BASEDIR} /我的回购< / URL>
  < /存储库>
< /存储库>

在那里安装使用您的第三方的lib 安装:安装文件与<一个href=\"http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#localRepositoryPath\"><$c$c>localRepositoryPath参数:

<击>

  MVN安装:安装文件-Dfile =&LT;路径到文件&gt; -DgroupId =&LT;为myGroup&GT; \\
                         -DartifactId =&LT; myArtifactId&GT; -Dversion =&LT; myVersion&GT; \\
                         -Dpackaging =&LT; myPackaging&GT; -DlocalRepositoryPath =&LT;路径&GT;

更新:看来,安装:安装文件忽略 localRepositoryPath 时使用插件的2.2版本。不过,它与2.3版及更高版本的插件。因此,使用该插件的全名指定版本:

  MVN org.apache.maven.plugins:Maven的安装,插件:2.3.1:安装文件\\
                         -Dfile =&LT;路径到文件&gt; -DgroupId =&LT;为myGroup&GT; \\
                         -DartifactId =&LT; myArtifactId&GT; -Dversion =&LT; myVersion&GT; \\
                         -Dpackaging =&LT; myPackaging&GT; -DlocalRepositoryPath =&LT;路径&GT;

最后,声明它像任何其他的依赖(但没有系统范围内):

 &LT;&依赖性GT;
  &LT;&的groupId GT; your.group.id&LT; /的groupId&GT;
  &LT;&的artifactId GT;的3rdParty&LT; / artifactId的&GT;
  &LT;&版GT;&X.Y.Z LT; /版本&GT;
&LT; /依赖性&GT;

这是恕我直言比使用系统范围,因为你的依赖将是一个好公民,被视为一个更好的解决方案(例如,它会被包含在装配等)

现在,我不得不提的是正道,以在企业环境中处理这种情况的(也许不是这里的情况)将使用公司资源库。

I have a proprietary jar that I want to add to my pom as a dependency.

But I don't want to add it to a repository. The reason is that I want my usual maven commands such as mvn compile, etc, to work out of the box. (Without demanding from the developers a to add it to some repository by themselves).

I want the jar to be in a 3rdparty lib in source control, and link to it by relative path from the pom.xml file.

Can this be done? How?

解决方案

I want the jar to be in a 3rdparty lib in source control, and link to it by relative path from the pom.xml file.

If you really want this (understand, if you can't use a corporate repository), then my advice would be to use a "file repository" local to the project and to not use a system scoped dependency. The system scoped should be avoided, such dependencies don't work well in many situation (e.g. in assembly), they cause more troubles than benefits.

So, instead, declare a repository local to the project:

<repositories>
  <repository>
    <id>my-local-repo</id>
    <url>file://${basedir}/my-repo</url>
  </repository>
</repositories>

Install your third party lib in there using install:install-file with the localRepositoryPath parameter:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> \ 
                         -DartifactId=<myArtifactId> -Dversion=<myVersion> \
                         -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>

Update: It appears that install:install-file ignores the localRepositoryPath when using the version 2.2 of the plugin. However, it works with version 2.3 and later of the plugin. So use the fully qualified name of the plugin to specify the version:

mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \
                         -Dfile=<path-to-file> -DgroupId=<myGroup> \ 
                         -DartifactId=<myArtifactId> -Dversion=<myVersion> \
                         -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>

Finally, declare it like any other dependency (but without the system scope):

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>3rdparty</artifactId>
  <version>X.Y.Z</version>
</dependency>

This is IMHO a better solution than using a system scope as your dependency will be treated like a good citizen (e.g. it will be included in an assembly and so on).

Now, I have to mention that the "right way" to deal with this situation in a corporate environment (maybe not the case here) would be to use a corporate repository.

这篇关于Maven的:添加一个依赖由相对路径罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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