Naturally, the debate rages on, but Wahanda builds it’s public facing website using Java plus assorted technologies, with Maven2 as our build and dependency tool.
Just make sure Julian (staunch PHP fan that he is) is looking the other way when you kick off a complete build and go for a coffee while it chunters away sucking every last drop of memory it can to complete it.
Having survived both make file and ant file madness at previous jobs, Maven has been a real relief. Yes, we had the odd computer says no moments (helped by Maven’s at times minimal documentation) but generally setting up the projects
and building them has been fairly easy.
What I hadn’t twigged until recently was the switches on the mvn command line that make this even easier and reduce the coffee break time.
From the mvn –help output, a few of note are:
-r Dynamically build reactor from subdirectories-pl Build specified reactor projects instead of all projects-am If project list is specified, also build projects required by the
list-amd If project list is specified, also build projects that depend on
projects on the list
Building the whole site
All the site project directories are kept in my workspace directory. so, to quickly build all the artifacts required for the whole site, running:
mvn -r clean install
from the workspace directory will build the lot in the correct order.
Hoorah!
The old way I used to do this was a noddy shell script which looped round the passed in directories and individually built each of them, e.g
./install database-commons *-bindings community-webapp site-webapp
would build all the specified projects by running
cd ; mvn clean install; cd ..
I had set up aliases to allow me to easily build groups of projects, but using the -r option is much faster since it doesn’t have to restart mvn for each project.
Selectively building projects
Using the -r option on its own is fine if you want that coffee break (I really should cut down). Using the -pl and -am options allows you to selectively build project. For example, if the community-webapp depends on the database-commons and the community-bindings artifacts, running:
mvn -r -pl community-webapp -am clean install
will build the community webapp and its dependencies in the right order. ‘community-webapp’ is the name of the directory the community-webapp artifact (pom file) is stored.
Using the -amd option works the other way around. If I have changed the database-commons artifact and I want to make sure it and all projects that depend on it work I can run:
mvn -r -pl database-commons -amd clean install
This will build database-commons, community-webapp, etc. Easy, huh.
To specify multiple projects, just put a comma separated list
mvn -r -pl database-commons,performance-logging -amd clean install
For bonus points, you may want maven to build multiple artifacts using command line wildcards, e.g *-binding for all the binding projects. Bit of a nuisance, but either getting tricky on the command line with
something like:
mvn -r -pl `echo *-binding | tr ' ' ','` -am clean install
or running the build through another noddy script performing the transform should do the job.
Or you can go back to tweaking ant scripts for a few weeks.
