Saturday 8 March 2008

Maven settings.xml that uses Artifactory, and restricts snapshot repository use

Hopefully this information is useful for other people who have Maven
projects but have to use other libraries and Maven plugins that are
still in the pre-release stage.

We are using Artifactory at work as a local repository proxy for Maven.

We also have a project that makes use of some snapshot libraries for
the CXF project, which is currently under incubation in Apache.

Previously, we were just using a <mirrors> but this resulted in Maven
getting its metadata settings both from the central repository and the
snapshot locations. We ended up getting snapshots of Maven plugins
that we never really wanted, as Maven would get plugin metadata from
both the repository types, and of course, the latest version would be
the snapshot ones.

To remedy this, we had to change settings.xml so that the only time
the Apache snapshot plugin repositories are used is in the projects
that require the CXF plugin and associated dependencies. The important
thing is to make sure the id element in the repository settings match
the repository setting id in the project pom.xml. The pom.xml settings
can still point to the live, non-proxied repository, but Maven will
first look at the id in that pom file and see if there is an entry
with the same id in the settings.xml

<settings>

<!-- uncomment this section and comment out the profiles section if
the Artifactory (local maven repository) is broken -->

<!--

<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>company.proxy</host>
<port>8080</port>
</proxy>
</proxies>
-->


<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<repository>
<id>central</id>
<url>http://internal.company.proxy:7070/artifactory/repo1
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>

<url>http://internal.company.proxy:7070/artifactory/snapshots-only
<releases>
<enabled>false</enabled>
</releases>
</repository>

<repository>
<id>everything-else</id>

<url>http://internal.company.proxy:7070/artifactory/releases
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

<!-- used by SomeWebService/pom.xml The id here
*must* match what's in the pom file -->
<repository>
<id>apache.org</id>

<url>http://internal.company.proxy:7070/artifactory/apache-m2-snapshots
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>

<!-- used by SomeWebService/pom.xml The id here
*must* match what's in the pom file -->
<repository>
<id>apache.incubating.releases</id>

<url>http://internal.company.proxy:7070/artifactory/apache-m2-incubating
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>

</repositories>


<pluginRepositories>

<pluginRepository>
<id>central</id>
<url>http://internal.company.proxy:7070/artifactory/repo1
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>

<url>http://internal.company.proxy:7070/artifactory/snapshots-only
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>

<!-- used by SomeWebService/pom.xml The id here
*must* match what's in the pom file -->
<pluginRepository>
<id>apache-plugin-incubating</id>

<url>http://internal.company.proxy:7070/artifactory/apache-m2-incubating
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>


</pluginRepositories>

</profile>

</profiles>

No comments: