Maven: Add 3rd party dependencies in project specific repository

Sometimes we need to use some commercial artifacts which are not available in the usual Maven repositories. These should of course be added to a repository hosted by your company or something like that, but sometimes it’s just simpler to stick those jars in the project directly and check them in with the rest of the code.

Found a nice way of doing that in the heroku devcenter documentation, so noting it down here for future reference.

Create repository

We’ll start with deploying an artifact to a repo folder in our project by using the following command. I split it up so it’s easier to read, but it should of course all be a single command.

mvn deploy:deploy-file

The group and artifact id you’d have to make up yourself of course. For example pull the artifact id from the library name and the group id from the main package used inside the library.

Remember to add this folder to your version control.

Define repository

Add the following to your pom.xml to let Maven know about the project repository we just created.


Define dependency

And finally just define the dependency in your pom.xml like you’d usually do.


Clean and simple.

  • Petr Vasiliev

    Thank you! This is very useful. Added to bookmarks.

  • Amine

    Good Tutorial ! But it can replacing Nexus OSS for example ?

    • Wouldn’t do it on a larger scale, but for small projects with for example just a few commercial 3rd-party libraries that doesn’t exist on the default maven repository and won’t be used anywhere else, sure.

      • Amine

        Ok thank you ! 🙂

        • Basically, as with all development: Keep it simple. Go ahead and do it, as long as it makes sense, but implement a proper repository the moment it starts to be a nuisance. And in this particular case, especially if the binaries change often, or even at all. One of the reasons why I did it for the mentioned project was that the libraries were proprietary and linked to a single released version of some software, so wasn’t really going to change.

          • Amine

            I understand : it’s like the 3rd party of Nexus OSS . Found your solution simple and adequate to projects with 80% of jars are internal : i’ll keep it in my mind to another day thnks