A few weeks ago I wrote an article about how I was investigating using build profiles in Maven POMs, for building Sakai against either the older style dependencies used in 2.4.x/2.5.x, or the newer kernel dependencies used in 2.6.x/trunk. Because the dependencies are completely different, if you need to build the same tool in either of these, you had to manually change the dependencies in every POM.
That article proposed a solution of adding -P <profile>
to the Maven build command. This worked great, but I wanted it to be even more automatic. It was by chance that I noticed a commit come through from Nuno Fernandes
who picked up the idea of build profiles and was looking at using them in Site Stats
We banged away a few emails and have finally come up with a solution to make it completely automatic!
How it works:
We needed to check for something that was always going to be present in a kernel based build, and never present in a 2.5.x based build, or vice versa. I tossed up the idea of checking for the the authz/authz-api/pom.xml since that is an integral part of Sakai, is present in 2.5.x, but has been moved to the kernel in 2.6.x+.
Nuno mentioned that he uses (and potentially other developers use as well) a different structure for contrib projects vs core Sakai projects, where the contrib projects are located outside the main Sakai code, and symlinked together via a ‘master’ link:
This was the key. Because Maven can follow symlinks, we can use the ‘master’ project as our launchpad. Enough guff, whats the solution!
<!-- Binds to Sakai Kernel K1 - for Sakai 2.6.0+ -->
<!-- Binds to Sakai pre Kernel K1 - for Sakai 2.4.x/2.5.x -->
Here we are still checking for the existence (or not) of a file, but with a path that is safe for both our cases, having contrib projects mixed with the main Sakai projects, and having them external and symlinked.
And with this approach, Maven can select the profile automatically without any extra flags!