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
Here is the sample configuration snippet for setting the
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:
- daily (this is the default value if you don’t specify any values
- interval:X (where X is an integer in minutes)
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
- 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.
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]
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:
mvn clean install -U
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.