| Maven Mythbusters #2 - Maven requires an internet connection to delete a directory |
|
|
|
| Monday, 11 January 2010 19:49 |
Maven seems to be one of those topics that brings out passion in many developers. In this series of articles, I want to take a look at some of the common myths and ideas that circulate about Maven, and see how they stand up to the light of scientific examination. Last time, we looked at the idea that Maven automatically updates for every build. This time we look at another myth quoted in this article: that Maven requires an internet connection to delete a directory. Myth Number 2: Maven requires an internet connection to delete a directory
In this issue, I want to look at another quote from the same blog entry, which suggests that Maven requires internet access to perform a "mvn clean" (and by implication I presume, to perform any other core task): "Maven is broken and wrong if it requires an internet connection to delete a directory" Let's look at this one a little closer. When you install Maven, you only install a small kernel - all of Maven's core functionalities are implemented by plugins. This is intentional (it's called modular design, actually). So the first time you use a particular lifecycle plugin (anything from "mvn clean" to "mvn deploy", and everything in between). And this will require network access - either to the central repository, or (preferably) to your local repository manager. This is normal behavior, but it can surprise new users, and certainly contributes to Maven's reputation of "downloading the internet". So let's reproduce this in laboratory conditions. I've deleted my local repository (you never do this in a real environment, of course) and run "mvn clean":
So this did indeed download stuff from the network, and did indeed require network access. But let's test this a little further. The quoted myth implies however that Maven needs network access every time it performs one of these core features. So let's see what happens when we run "mvn clean" again:
This time, Maven required no network access, and downloaded no files. In fact, Maven will never require you to download anything related to these core plugins more than once. Maven's core plugins are bound to the version of Maven you are running - once you have downloaded them for one project, they will be available for all other Maven builds on your machine.
Now the blogger may have a point here - maybe Maven should download the core lifecycle plugins and install them into the local repository during the installation process. But Maven uses different plugins for different project types (JAR, WAR, EAR...), so that would make for a pretty big download, not all of which would necessarily be required for your particular projects. But if that's what it needs to keep the users happy, why not? However the idea that Maven systematically needs network access for core functions such as "mvn clean" is clearly busted. (The title and some of the images of this blog were of course shamelessly stolen from the great and highly scientific MythBusters TV series.)
Bookmark
Email this
Trackback(0)
Comments (5)
![]() written by voo, January 12, 2010
Did you try offline mode ? "mvn clean -o"
written by Alex R, January 12, 2010
... is to show the smallest pom.xml file required to build the simplest java project, and compare that to equal Ant script.
People often complain that pom files are bloat of xml. But in my experience they mostly grow because of large set of dependencies included. Otherwise it is easy to keep poms short and readable. There is a myth about Maven that it is better suited for large projects, and with small ones you are better to go with Ant. I think this is not true, and you are better to use Maven with both small and large projects. The shortest pom.xml file I came across only requires declaring project group and artifact id, project name and single JUnit dependency. I bet that equal Ant file would be bigger and messier soup of XML as one should define compile, test and package tasks from scratch. These steps you get from Maven for free. Cheers, Alex written by Tom Willis, January 13, 2010
I don't think you busted the myth but at least explained why maven may exhibit this behavior.
written by Carsten Schlipf, January 13, 2010
Maven can be used perfectly offline. First there is the already mentioned -o switch to prevent any repository lookups. Second the dependency plugin can download all dependencies, when a network connection is available and reuse them later: Just run
mvn dependency:go-offline Unfortunately go-offline does not always download everything, so after deleting your local repository, you should first run an online build, then dependency:go-offline and afterwards you can be pretty sure that you can run almost everything in offline mode. Write comment
|
|