How to force maven to update dependences' versions daily?
We are using maven 2.2.1 and are pretty happy with how the things are going. Recently we've started to use dependency versions' ranges like this:
<dependency>
<!-- com.google.inject.Guice -->
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>[3,4)</version>
</dependency>
But now I am facing a problem that maven checks for new versions of every such dependency at every build, which makes builds painfully slow:
[INFO] artifact com.google.inject:guice: checking for updates from internal
[INFO] artifact com.google.inject:guice: checking for updates from central
Here is how my repositories declaration looks like:
<repositories>
<repository>
<id>internal</id>
<url>http://internal.repo.local/nexus/content/repositories/releases</url>
</repository>
</repositories>
I've checked repository configuration as far as I can understand, looked through default values for <repository/>
section and parent POM inheritance.
I have already tried changing updatePolicy
with no success. Looks like all policies are working with only SNAPSHOT
management and are ignored for version checks.
I've found a workaround of -o
开发者_Go百科 command line option, but... I would like to check for external version at least sometimes and idea of creation cron
-based maven scheduling that updates local repository daily does not sound for as an appropriate solution.
First, as a previous commenter said, your build isn't reproducible with build ranges... which is the whole point of Maven. I hope you understand the significance of that, so I'll just answer your question.
Simply set the update policy of the repository:
<repositories> <repository> <id>internal</id> <url>http://internal.repo.local/nexus/content/repositories/releases</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>
EDIT: I answered the original question out of context, sorry.
The best way to answer this is to figure out why Maven is updating every day. This may be caused by your ranged dependency, or it may be a bug in Maven. I will let you do the footwork on that...
I think what you're actually trying to get at is, "How do I keep maven from going out to central every time I do a build and slowing me down?" I had this exact problem while working overseas, the internet connection was very slow. We setup a nexus proxy, and I had to figure out a way to force all lookups to hit the proxy.
Change the <updatePolicy> to something that suits your needs. Daily would probably work unless you have more specific needs.
Next, edit your settings.xml and add this section:
</activeProfiles> <mirrors> <mirror> <id>internal-mirror</id> <url>http://internal.repo.local/nexus/content/repositories/releases</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> </settings>
This will force all dependency lookups to go through your internal nexus instance, hitting the nexus cache, and immensely speeding up your build.
精彩评论