Why is Maven downloading the maven-metadata.xml every time?
Solution 1:
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.
Solution 2:
It is possibly to use the flag -o,--offline "Work offline"
to prevent that.
Like this:
maven compile -o
Solution 3:
I suppose because you didn't specify plugin version so it triggers the download of associated metadata in order to get the last one.
Otherwise did you try to force local repo usage using -o ?