Force maven to fetch dependencies from remote

Seralahthan
2 min readDec 15, 2019

--

Sometimes during the maven project build, some of the dependencies might get partially downloaded from the remote repository manager (Maven Central Or Nexus) due to some network issues.

In such cases, the first time the build will fail. When we try to build the project again, we are most likely to get the following error message.

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project saml2-web-app-pickup-manager: 
Could not resolve dependencies for project org.wso2.samples.is:saml2-web-app-pickup-manager:war:4.1.0:
Failure to find org.wso2.samples.is:claim-manager:jar:4.1.0 in http://maven.wso2.org/nexus/content/groups/wso2-public/ was cached in the local repository, resolution will not be reattempted until the update interval of wso2-nexus has elapsed or updates are forced
at
org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies (LifecycleDependencyResolver.java:269)

Here the build failure occurs as maven tries to build from the partially fetched dependency cached in the local repository.

Maven fetches updates from the remote repository after the update interval elapses. By default, the update interval is daily. Update interval can be configured for releases and snapshots by configuring the updatePolicy in the pom file.

Maven doesn’t fetch dependency updates (new version releases) Or reattempt to fetch dependencies cached in the local repository before the update interval. There are few ways we can overcome the error “resolution will not be reattempted until the update interval of <Remote_Repository_Name>”

  • Force maven to fetch dependencies from the remote repository while building the project.
  • Modify the update interval.

Force maven to fetch dependencies from the remote repository while building the project.

We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.

mvn clean install -U -X

Here,
-U,--update-snapshots :
Forces a check for missing releases and updated snapshots on remote repositories.

-X,--debug : Produce execution debug output.

Modify the update interval.

In the pom.xml file of the project, there will be the repositories and pluginRepositories configured as below.

<repositories>
<repository>
...
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
...
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
...
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
...
</pluginRepository>
</pluginRepositories>

Make sure to change the <updatePolicy>always</updatePolicy> for the releases (if needed for the snapshots as well). Generally, snapshots are configured with <updatePolicy>never</updatePolicy>.

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.

Refer to the official maven documentation [1] for additional details.

References :

[1] http://maven.apache.org/settings.html#Repositories

Thanks for reading!!!

--

--

Seralahthan

Consultant - Integration & CIAM | ATL@WSO2 | BScEng(Hons) in Computer Engineering | Interested in BigData, ML & AI