Skip to content

Wakaleo Consulting

  Home Blog Maven Mythbusters #2 - Maven requires an internet connection to delete a directory
  • Expertise in Automated Acceptance Tests and ATDD
  • Training and Mentoring in Test Driven Development
  • Expertise in Continuous Integration and Continuous Deployment
  • Expertise in quality development and testing practices
  • Training and Mentoring in Test Driven Development
  • Expert Jenkins/Hudson training and mentoring
  • Expertise in Continuous Integration and Continuous Delivery
  • Training and Mentoring in Test Driven Development
  • Training and Mentoring in Test Driven Development
Maven Mythbusters #2 - Maven requires an internet connection to delete a directory PDF Print E-mail
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":

$ 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/
plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
3K downloaded  (maven-clean-plugin-2.2.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/maven/
plugins/maven-plugins/10/maven-plugins-10.pom
7K downloaded  (maven-plugins-10.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/
maven/maven-parent/7/maven-parent-7.pom
20K downloaded  (maven-parent-7.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/
apache/4/apache-4.pom
4K downloaded  (apache-4.pom)
Downloading: http://localhost:8081/nexus/content/groups/public/org/apache/maven/
plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.jar
11K 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.)

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close



Trackback(0)
Comments (5)Add Comment
0
Did you try offline mode ? "mvn clean -o"
written by voo, January 12, 2010
Did you try offline mode ? "mvn clean -o"
0
Another maven mythbusters idea
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

0
...
written by Sakuraba, January 12, 2010
Give those Ant guys hell already!
0
Busted?
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.
0
dependency:go-offline
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

busy