JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

Maven : updatePolicy Configuration in Settings XML file

March 2, 2016 by Krishna Srinivasan Leave a Comment

One of the most common thing when working with dependency management is how often our local repository has to sync up with the remote repository. Maven has updatePolicy settings for specifying the frequency to check the updates in the repository. Most of the times this value is left blank in the configuration files, the default value is daily. This tutorial explains the use of this element in the settings.xml (global configuration file used for maven repository) file and what are the possible values that can be used for the updatePolicy element.

Maven updatePolicy Settings
Maven updatePolicy Settings

Here is the sample configuration snippet for setting the updatePolicy value:

[code lang=”xml”]
<pluginRepositories>
<pluginRepository>
<id>Releases</id>
<url>http://<host>:<port>/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
[/code]

In the above example snippet, the settings tells the Maven that Releases repository (configured in local) has to check the remote repository for the artifacts every day. If it finds any updates to the artifacts, then it will download to the local repository. The timestamps are compared to the local POM’s timestamps (stored in a repository’s maven-metadata file). The possible choices for updatePolicy element are:

  • always
  • daily (this is the default value if you don’t specify any values
  • interval:X (where X is an integer in minutes)
  • never

Note that updatePolicy element itself an optional configuration. If don’t specify anything, it will take the default value. However, it is recommended to use always to download the latest updates available when ever uploaded to the repository. But, you should never use the value never for the updatePolicy. Sometimes, you may get the following error in the maven pom.xml file.

  • Also Read : How to create simple Java project using Maven

updatePolicy also applies to Maven meta data, For example, which versions are available and which one is the most current one. So, if there are any artifact versions already present in your local Maven repository, Maven will never download any version that is not yet present in your local repository. It will not download the newer versions from the remote repository.

[code]
Failure to find org.jfrog.maven.annomojo:maven-plugin-anno:jar:1.4.0 in http://myrepo:80/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of MyRepo has elapsed or updates are forced -> [Help 1]
[/code]

The cause of this issue is that, in the local repository the file is not available. You can solve this problem by forcing the updates like this:

[code]
mvn clean install -U
[/code]

Here -U means force updates.

Also Read : Create Web Application using Maven

I hope this tutorial helped you to understand the concepts of using updatePolicy element in the maven’s settings file. If you have any questions, please write it in the comments section.

 

Filed Under: Java Tagged With: Apache Maven Configurations

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved