Dmitry Sergeev
Dmitry Sergeev

Reputation: 180

Maven repository order

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.

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

Upvotes: 3

Views: 2024

Answers (1)

A_Di-Matteo
A_Di-Matteo

Reputation: 27812

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>

You can have your fork as:

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

Advantages of this approach:

  • 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:

  • if you are working in a company, add the company name to the classifier, so if a contract/external needs to work with it, it is immediately clear that it was a fork made by the concerned company
  • if it's a patch or an additional feature (or for a specific OS or Java version), try to make it clear as well
  • Use your common sense, like if it was a tag and you would use it later on for search

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

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.

Upvotes: 3

Related Questions