3

I have a dependency in pom on some library. I want to make some changes in it, test it locally and if it will work fine - deploy it to remote repo. So I have locally made some changes in this library, installed it as a jar, and want to replace in my main project remote library with the local one.

What is proper way to do it?

Oleksandr Riznyk
  • 758
  • 1
  • 8
  • 19
  • 1
    Depends. Do you use Nexus or Artifactory? Is this your own library (or a third party library)? What kind of build tool are you using? What have you tried? – Elliott Frisch Jan 10 '19 at 12:43
  • Possible duplicate of [https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project] – Sabesh Jan 10 '19 at 12:43
  • Note that the Maven mindset is that non-SNAPSHOT artifacts are in general frozen and any copy is as good as any other so caches may be disruptive and your builds will not be reproducible. This mean, either use SNAPSHOTs or be very careful what you do. Creating a new artifact may be the best solution. – Thorbjørn Ravn Andersen Jan 10 '19 at 13:20

3 Answers3

2

When resolving dependencies, Maven looks in your local repository ($HOME/.m2/repository). So if you have installed your modified dependency into your local repository (e.g. through mvn install) then when you build your main project, it will be used.

To make this more obvious, you may want to change the versions being used in both the library and your main project POM, so that you can be sure your version is being used for testing.

You may also find this question/answer useful: How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts?

nightowlengineer
  • 219
  • 1
  • 16
2

You can override default maven repository in project's pom:

 <repositories>
    <repository>
      <id>central</id>
      <url>file://d:/repo</url>
    </repository>
  </repositories>
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

Maven first looks in your local repository in

C:\Users\User\.m2\repository

and if it can't find the library, then it looks in remote repos. If I understand your question correctly, this should be happening automatically as long as you point the correct version in the POM.