Warning: Use of undefined constant fixed - assumed 'fixed' (this will throw an Error in a future version of PHP) in /home/webtro13/domains/farenda.com/public_html/wp-content/themes/moments/header.php on line 65

Java Programming Tutorials

Java programming tutorials with many code examples!

Maven use company repository

Maven use company repository (Nexus)

In this post we’ll show how to configure Maven to download project libraries from your company’s repository/mirror instead of the Internet.

In most cases, when developing software in corporations, you would like to download all project libraries from a repository (Nexus) located in corporate network, which is much faster than from the Internet.

Mirror repository in settings.xml

Configuration for all your Maven projects can be done in ~/.m2/settings.xml (.m2 directory located in your home/user directory):

<?xml version="1.0" encoding="utf-8"?>
  <!-- other configuration if any -->
    <!-- you can setup more mirrors, but usually it's one -->
      <name>Your Company Mirror</name>
  <!-- other configuration if any -->

Just use the address of your company’s Nexus repository and make sure to set path (here /content/groups/all_repos) to what is used in your company’s Nexus.

Maven mirrorOf syntax

The key part is configuration is mirrorOf. It allows to select, using ids or wildcards, which repositories should be mirrored:

  • *
    Tells Maven that all libraries should be taken from company’s repository.
  • external:*
    Fetch all from company repo, except those on the localhost and from files (sometimes libs are in a project’s subdirectory).
  • repoId1,repoId2
    Use company repository instead of repositories with these ids. For others download normally.
  • *,!repoId
    Mirror everything except (note the exclamation mark) repository with id repoId.

Now, when you run maven package or just import a project in your IDE, then Maven will download packages from the URL provided above.

Voila! :-)

Share with the World!