Why is Maven downloading the maven-metadata.xml every time?
Look in your settings.xml
(or, possibly your project's parent or corporate parent POM) for the <repositories>
element. It will look something like the below.
<repositories>
<repository>
<id>central</id>
<url>http://gotoNexus</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
</repositories>
Note the <updatePolicy>
element. The example tells Maven to contact the remote repo (Nexus in my case, Maven Central if you're not using your own remote repo) any time Maven needs to retrieve a snapshot artifact during a build, checking to see if there's a newer copy. The metadata is required for this. If there is a newer copy Maven downloads it to your local repo.
In the example, for releases, the policy is daily
so it will check during your first build of the day. never
is also a valid option, as described in Maven settings docs.
Plugins are resolved separately. You may have repositories configured for those as well, with different update policies if desired.
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://gotoNexus</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
Someone else mentioned the -o
option. If you use that, Maven runs in "offline" mode. It knows it has a local repo only, and it won't contact the remote repo to refresh the artifacts no matter what update policies you use.
How do I prevent Maven from downloading maven-metadata.xml for an artifact that I already have in my repo?
Maybe the update policies need to be specified explicitly. See this answer: Why is Maven downloading the maven-metadata.xml every time?
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://gotoNexus</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
maven-metadata.xml keeps getting requested when building
Gradle usually needs to download a maven-metadata.xml
file, if
- you use a dynamic/changing version for one of your dependencies, and
- the time to live (TTL) in the dependency cache is over.
For (1) you should look for versions like 1.2.3-SNAPSHOT
or 1.2.+
on your declared dependencies (or at ./gradlew dependencies
for simplicity). If you have any such versions, do you really need them? Using fixed versions like 1.2.3
should be faster.
For (2), have you maybe changed the default TTL threshold or do you maybe always build with --refresh-dependencies
? If not, then the slowness should at least not occur more often than once a day.
If the above doesn’t help, then maybe try running your build with --info
or --info --refresh-dependencies
and carefully watch the log output. That should show which dependency and/or which repository is the culprit (i.e., the one on which the logging is stuck for the longest time). If you find such a culprit, then you could look into things like
- replacing the dependency (or the repository),
- improving the speed of the repository server or the network, or
- pruning old snapshot versions from the problematic
maven-metadata.xml
file (if you control the repository).
If all this still doesn’t turn up actionable items, then maybe it could be worth looking for bigger maven-metadata.xml
files in your Gradle dependency cache. Maybe the repeated download of such big files is the issue and one of the approaches from the previous list could help. Here’s an idea for how to find the ten biggest maven-metadata.xml
files (with a Unix shell command):
find ~/.gradle/caches/modules-2/resources-* \
-name maven-metadata.xml \
-printf '%s\t%p\n' \
| sort -k1 \
| tail
Maven: metadata xml files downloaded often from remote repositories
The most important thing is to start using a repository manager furthermore check the configuration in your settings.xml file which can be configured to check the remote repositories (update policy).
How do I prevent Maven from downloading artifacts every time?
You may control the update frequency by configuring repositories in the $USER_HOME/.m2/settings.xml
file. Specifically, change the updatePolicy
to a value that results in less frequent updates.
This Stackoverflow answer has more detail.
Maven Resolver always downloads maven-metadata.xml from remote repositories
Well...
// this one prevents maven from downloading metadata.xml
// if I understand properly it tries to find maven-metadata-0.xml
// in local repository and in case of failure tries remote repositories
session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(true, false));
// this one prevents maven from creating _remote.repositories files
// in local repository, yours: in my local repo, but wasn't downloaded from central
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, new LocalRepository(LOCAL_REPO_DIR, "simple")));
Related Topics
How to Compile a Java Source File Which Is Encoded as "Utf-8"
When to Use Atomicreference in Java
Compilation Error: Identifier Expected
How to Check If a Date Object Equals Yesterday
How to Read a File from a Certain Offset in Java
Why Is "Final" Not Allowed in Java 8 Interface Methods
Spring MVC Type Conversion:Propertyeditor or Converter
Difference Between One-To-Many, Many-To-One and Many-To-Many
Can Spring Security Use @Preauthorize on Spring Controllers Methods
Jbutton Actionlistener - Gui Updates Only After Jbutton Is Clicked
How to Detect Language of User Entered Text
Difference Between "On-Heap" and "Off-Heap"
Hibernate Sessionfactory VS. JPA Entitymanagerfactory
Can Anyone Recommend a Simple Java Web-App Framework