Skip to main content

Maven Mythbusters #2 - Maven requires an internet connection to delete a directory

Posted by johnsmart on January 11, 2010 at 8:16 PM PST

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":

 


$ rm -Rf ~/.m2/repository
$ mvn clean
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   Tweeter
[INFO]   Tweeter domain model
[INFO]   Tweeter service layer
[INFO]   Tweeter web application
[INFO] ------------------------------------------------------------------------
[INFO] Building Tweeter
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/maven/
plug...
downloaded  (maven-clean-plugin-2.2.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/maven/
plug...
downloaded  (maven-plugins-10.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/
maven/mave...
downloaded  (maven-parent-7.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/
apache/4/a...
downloaded  (apache-4.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/maven/
plug...
downloaded  (maven-clean-plugin-2.2.jar)
...
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory /Users/johnsmart/Projects/wakaleo-training/tdd-training/
lab-solutions/tweeter/tweeter-web/target
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Tweeter ............................................... SUCCESS [8.806s]
[INFO] Tweeter domain model .................................. SUCCESS [0.044s]
[INFO] Tweeter service layer ................................. SUCCESS [0.054s]
[INFO] Tweeter web application ............................... SUCCESS [2.518s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Wed Jan 06 20:59:41 NZDT 2010
[INFO] Final Memory: 10M/80M
[INFO] ------------------------------------------------------------------------

 

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:

 


$ mvn clean
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   Tweeter
[INFO]   Tweeter domain model
[INFO]   Tweeter service layer
[INFO]   Tweeter web application
[INFO] ------------------------------------------------------------------------
[INFO] Building Tweeter
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tweeter domain model
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tweeter service layer
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tweeter web application
[INFO]    task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Tweeter ............................................... SUCCESS [0.780s]
[INFO] Tweeter domain model .................................. SUCCESS [0.007s]
[INFO] Tweeter service layer ................................. SUCCESS [0.016s]
[INFO] Tweeter web application ............................... SUCCESS [0.408s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Wed Jan 06 21:16:09 NZDT 2010
[INFO] Final Memory: 9M/80M
[INFO] ------------------------------------------------------------------------

 

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.)

Related Topics >>

Comments

Myths vs history

Is it not true that some of this behaviour was actually true for earlier versions of Maven? Just like there was a time when Java was rather slow and the garbage collector needed a lot of help. I distinguish between (ancient) history and myths.