Search This Blog

Loading...

Tuesday, January 5, 2010

Maven snapshot dependencies trick

We have a web-application that consists from two main parts - client (*.css, *.js etc) and server (*.java). It's packaged as a Maven2 project, so, there are dedicated projects for those parts and separate project that defines custom assembly. We use snapshot versions during active development and I encountered a problem with default maven policy for their management.

The problem is that snapshot dependencies at local repository are synced with remote repository once per day by default. That means that if more than one version of the same artifact used as a snapshot dependency is deployed to remote repository, your local repository doesn't contain up-to-date version by default.

Here is a maven documentation snippet about that - Repositories:


updatePolicy: This element specifies how often updates should attempt to occur. Maven will compare the local POM's timestamp (stored in a repository's maven-metadata file) to the remote. The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never.


I.e. default policy is to sync snapshot dependency once per-day.



However, that can be changed easily by setting update policy to 'always':

<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>mycompany</id>
<name>MyCompany repository</name>
<url>https://mycompany.com/content/repositories/mycompany</url>
</repository>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>mycompany-snapshot</id>
<name>MyCompany snapshot repository</name>
<url>https://mycompany.com/content/repositories/mycompany-snapshot</url>
</repository>
</repositories>

No comments:

Post a Comment