» Eclipse Maven plugin: counterproductive / Reply to comment
Reply to comment
Eclipse Maven plugin: counterproductive
When I started working on a new project a few months ago, we decided to
use Maven 2 as we were to use lots of open source projects. I only used
Ant previously,
and it seemed Maven would help me to manage all the dependencies,
direct and indirect.
Sure, your project and build system is setup in minutes, but once you want to do a bit more than just compile/jar/jetty6:run it feels like black magic, and reading the book didn't really helped. Also, as Stéphane shows, the dependency mess grows quickly with the number of direct dependencies your project has...
Another apparently nice thing that comes with Maven is the Eclipse plugin. Add a new dependency in your POM within Eclipse, save the file, and instantly the corresponding artifacts are downloaded. Also, a new "Maven2/Add dependency" menu appears, that allows you to do plain text searches in the central repository. And even better: if your source code refers to a class that's not in the project's classpath, the plugin finds the artifacts where that class is declared and allows you to add them as a new dependency. Sweet!
Now this plugin, after some time, proves to be more annoying than helpful, and worse: counterproductive.
The first bad thing is that it too often requires rebuilding your entire project: when you change the POM (acceptable as you change the classpath), and when you start Eclipse (why is it needed?). This plugin has a nice option: in the preference panel, checking the "Download artifacts sources" allows to attach the source code -- if available -- to 3rd party libraries. This is very convenient for completion information and debugging. Alas, very few Maven artifacts have this and rebuilding the project with this option takes ages as Maven tries to download all missing source artifacts, even in offline mode. It takes ages! And this dumb thing does it again for all the projects even if they share the same dependencies!
The second bad thing is the freshness of the artifact database used for searching. At first I thought it was querying some webservice in the background. But after a few weeks, I found that some new versions of some of the libraries I was using were missing, so I updated the version by hand in the POM, thinking about some update delay in the the remote service. But more and more new dependencies were missing and today I decided to understand where the search results were coming from. First thing is to use a debugging proxy to see what happens when you search for a new artifact. Result: nothing! No request! Nada!
So what datasource is used by the query? Looking at the plugin contents, there's a file named
So, what's the value of a plugin that slows down your IDE by attempting useless downloads and provides you with outdated information? Not much.
If you want to use the latest versions of the artifacts you add, browse the central repository and use the search service of mvnrepository.com!
Once you found your artifact, add it to your POM and run the following command in your project directory:
Note: the
Sure, your project and build system is setup in minutes, but once you want to do a bit more than just compile/jar/jetty6:run it feels like black magic, and reading the book didn't really helped. Also, as Stéphane shows, the dependency mess grows quickly with the number of direct dependencies your project has...
Another apparently nice thing that comes with Maven is the Eclipse plugin. Add a new dependency in your POM within Eclipse, save the file, and instantly the corresponding artifacts are downloaded. Also, a new "Maven2/Add dependency" menu appears, that allows you to do plain text searches in the central repository. And even better: if your source code refers to a class that's not in the project's classpath, the plugin finds the artifacts where that class is declared and allows you to add them as a new dependency. Sweet!
Now this plugin, after some time, proves to be more annoying than helpful, and worse: counterproductive.
The first bad thing is that it too often requires rebuilding your entire project: when you change the POM (acceptable as you change the classpath), and when you start Eclipse (why is it needed?). This plugin has a nice option: in the preference panel, checking the "Download artifacts sources" allows to attach the source code -- if available -- to 3rd party libraries. This is very convenient for completion information and debugging. Alas, very few Maven artifacts have this and rebuilding the project with this option takes ages as Maven tries to download all missing source artifacts, even in offline mode. It takes ages! And this dumb thing does it again for all the projects even if they share the same dependencies!
The second bad thing is the freshness of the artifact database used for searching. At first I thought it was querying some webservice in the background. But after a few weeks, I found that some new versions of some of the libraries I was using were missing, so I updated the version by hand in the POM, thinking about some update delay in the the remote service. But more and more new dependencies were missing and today I decided to understand where the search results were coming from. First thing is to use a debugging proxy to see what happens when you search for a new artifact. Result: nothing! No request! Nada!
So what datasource is used by the query? Looking at the plugin contents, there's a file named
central.zip.
This is actually a Lucene
index. Examining it with Luke
(a must-have for Lucene users) shows all artifacts, with their version,
date, and the name of all the public classes they contain. This is
where it all comes from! Nice idea, but that means also that it quickly
becomes outdated if you (and the plugin's developers) don't update it
regularly!So, what's the value of a plugin that slows down your IDE by attempting useless downloads and provides you with outdated information? Not much.
If you want to use the latest versions of the artifacts you add, browse the central repository and use the search service of mvnrepository.com!
Once you found your artifact, add it to your POM and run the following command in your project directory:
mvn -Declipse.downloadSources=true eclipse:eclipseThis creates the
.project and .classpath files
and (tries to) download the source files for
the artifacts, outside of Eclipse. And it does it once, and not every time
you start Eclipse or rebuild your project.Note: the
downloadSources options isn't
documented in the Eclipse
plugin doc as one would expect, but in one
of the many "mini-guides". I knew this option existed, but it
took me several Google searches to find it...