Maven存储库顺序 [英] Maven repository order

查看:102
本文介绍了Maven存储库顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储在repo.maven.apache.org中的fork工件,它有相同的组,工件ID和版本。我的fork存储在my.repo.hostname中。

I have a fork artifact from one who stored in repo.maven.apache.org, it has the same group, artifact id and version. My fork is stored in my.repo.hostname.

如何强制Maven使用我的存储库中的工件,而不是来自Maven Central?

How can I force Maven to use artifact from my repository, not from Maven Central?

推荐答案

在分配原始工件时,应使用分类器进行区分。

When forking an original artifact, you should use classifiers to make a distinction.

因此,如果原始工件是:

So, if the original artifact was:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>library</artifactId>
    <version>1.0</version>
</dependency>

您可以将叉子设为:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>library</artifactId>
    <version>1.0</version>
    <classifier>myfork</classifier>
</dependency>

此方法的优点:


  • 你保持原始Maven坐标的可追溯性,因此可以清楚地看到叉子的制作位置

  • 你说清楚它是一个不同的版本(或一个叉子)该特定工件的特定版本

  • 如果其他人正在查看您的POM,并且尝试在另一台无法访问您的存储库的计算机上构建它,则不会产生混淆(提供fork)然后具有不同的行为甚至错误,因为使用原始的:可维护性是一个很大的收获。

  • 您使用Maven标准(见下文)

  • You keep traceability with original Maven coordinates, so it is clear from where the fork was made
  • You make it clear it is a different version (or a fork) of that specific version of that specific artifact
  • You don't create confusion if someone else is looking at your POM and, say, tries to build it in another machine with no access to your repository (providing the fork) and then having different behavior or even errors because using the original one: maintainability is a big gain.
  • You use Maven standards (see below)

对于分类器名称(它是一个免费字符串),我经常发现提供其他信息很有用:

For the classifier name (it's a free string) I often found useful to provide additional information:


  • 如果您在公司工作,请将公司名称添加到分类器中,因此如果合同/外部需要使用它,很明显它是由co制造的分支ncerned公司

  • 如果它是补丁或附加功能(或特定操作系统或Java版本),请尝试清楚说明

  • 使用你的常识,就像它是一个标签,你稍后会用它来搜索

在这种情况下使用分类器它是也是Maven推荐的方法,来自官方文档

Using classifier in this case it is also a Maven recommended approach, from official documentation:


分类器允许区分从同一个POM构建但内容不同的工件。它是一些可选的任意字符串 - 如果存在 - 将附加到版本号之后的工件名称。

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

因此,不会出现存储库订单或任何其他类型的问题,您的构建将获得清晰度,可重复性和可维护性。希望它可能有所帮助。

As such, no repository order or any other type of issue would be present and your build will gain clarity, reproducibility and maintainability. Hope it might help.

这篇关于Maven存储库顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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