Using Maven for Squale

Maven is a build and project management tool that we use for the Squale project. Amongst all its benefits, one of the most valuable is the dependency management. If you grab the source code of Squale, you will see that almost no JAR is in the Subversion repository: this is because the set up and build process completely relies on Maven to download them when required. Which is the case when you get the source code for the first time, but also when the dependencies have been updated.

This mini-guide will tell you:

  • how to install Maven and set up everything in Eclipse so that it is easier to use.
  • how to call it the first time you grab the sources from Subversion, so that you can get all the required JARs to run it locally or to build it for a target environment.

Maven install and setup in Eclipse

The first step is to download and install Maven on your computer. Please refer to the online documentation for that purpose.

Once you can run a "mvn -v" command in a shell, you may want to be able to launch Maven from within Eclipse. To achieve that, you have several possibilities:

  • use some Eclipse plugins that embed Maven,
  • or simply create an external tool that calls Maven: this solution is really easy to do and does its job very well.

Then, you need to add this settings.xml file into your "$user_home/.m2" folder (under Windows, "$user_home" is generally "C:\Documents and Settings\your-name\").

The last step is to create in Eclipse a classpath variable entry that refers to your Maven local repository folder. Go to "Java -> Build Path -> Classpath variables" and create a new one called "M2_REPO" that points to wherever your local repository is (normally, it is in the "$user_home/.m2/repository" directory under your user home folder).

First build with Maven

A first build is required as we do not store all the dependencies of Squale in Subversion: Maven takes care of them (thanks to the pom.xml file) and will grab them from the internet repositories the first time it needs them. If you look to Eclipse ".classpath" files, you will notice that they refer to the M2_REPO classpath variable.

To achieve this, run a "mvn install" command in the "squale" folder (https://svn.squale.org/squale/squale/trunk/Squale/squale/ if you build from trunk). Once the build is successful, you will be able to refresh your Eclipse so that your sources can compile without any error.