Configuring Maven

Introduction

For setting up Maven to use Artifactory proxy, just configure a Maven repository with the following URL:
<host>:<port>/artifactory/repo
This URL will make artifactory look through all repositories (local and remote), for any artifacts maven is fetching.

You can also place the name of the local repository to limit artifactory search to this local repository and all remote repositories.
The maven repository URL should look like: <host>:<port>/artifactory/<local_repo_name>

Classic Setup

If your Artifactory is configured correctly, you should override the built-in central and snapshots repositories of Maven, so that no request will be ever sent directly to them.
Insert the following into your parent POM or settings.xml (under an active profile):

<repositories>
    <repository>
        <id>central</id>
        <url>http://[host]:[port]/artifactory/repo</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>snapshots</id>
        <url>http://[host]:[port]/artifactory/repo</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>http://[host]:[port]/artifactory/plugins-releases</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>snapshots</id>
        <url>http://[host]:[port]/artifactory/plugins-snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

"Mirror-any" Setup

With Maven 2.0.5 and above, you can also use the new "mirror any" feature instead of the above, and have Artifactory act as a redirecting proxy for any Maven repository, including ones defined inside dependency POMs.
Insert the following into your settings.xml:

<mirrors>
    <mirror>
      <id>artifactory</id>
      <mirrorOf>*</mirrorOf>
      <url>http://[host]:[port]/artifactory/repo</url>
      <name>Artifactory</name>
    </mirror>
</mirrors>

Caveat

There seem to be artifact resolution issues with using the "mirror-any" technique under Maven 2.0.7 & 2.0.8.

If you are using one of these versions of Maven, please prefer using the first technique (overriding the built-in Central and Snapshots repositories of Maven) which will always work as expected.

Labels

 
(None)
  1. Mar 25

    nodje says:

    You have to have manually configured "pluginsreleases" and "pluginssnapshots" to...

    You have to have manually configured "plugins-releases" and "plugins-snapshots" to be able to use this configuration.
    Replace it by /repo if you don't have those repositories configured.