Building m2 projects with CruiseControl
Thursday, June 9th, 2005While maven2 is not yet officially released, some projects have started adopting it for their build, because of the many improvements it brings, in particular better dependency management, increased flexibility and simpler configuration.
Maybe are you considering using it but wonder how to integrate it with your other tools. What about continuous integration?
Maven2 comes with it’s own Continunous Integration tool called continuum, and if you use maven2 projects you should probably try this tool. But what if you already use CruiseControl? As of this writing, CruiseControl doesn’t support Maven2 builders. It probably will some day. Until then, how can you build a m2 project using CruiseControl?
What are our options?
- use a builder that supports generic build scripts. Unfortunately (and strangely) CruiseControl doesn’t yet support that
- wrap our m2 script in a supported builder. E.g. by making ant call m2 using the appropriate Exec task
- trick CruiseControl into believing it is building a known builder (maven1). For that we can define a custom
mavenscriptthat in fact calls m2 transparently
The third option is interesting. After all maven1 and maven2 are similar. For that a little bit of work is required and the following issues must be solved:
- the current maven builder requires 3 attributes:
goal,mavenscriptandprojectfile. Given these attributes the MavenBuilder will trigger the following command:yourscript -p yourprojectfile yourgoals
- the builder parses the maven output to understand what it going on. So the mavenscript will have to convert the mavn2 output into maven1 like output.
That doesn’t sound too hard. The approach I describe below follow this solution. It is customized to work on Unix and assumes that you are already familiar with m2 and CruiseControl, and that both are properly installed.
First let’s create a new project in your config.xml. Add the bootstrappers, listeners, publishers your need, exactely like if you were to build a maven1 project. The main difference is in the builder definition:
<schedule>
<maven goal="ignored"
mavenscript="${projectdir}/m2wrapper.sh"
projectfile="${projectdir}/dummy"/>
</schedule>
(ignore the \” appearing in this code block. They really should be “. It’s wordpress playing tricks with me.)
You can note here that I am using ant style properties in my config.xml. This is a nice feature of the forthcoming CruiseControl 2.2.2. It will make your config.xml much simpler.
Note also that I defined a dummy project file. The MavenBuilder class checks that the file exists so we will have to create it.
cd checkout/your_project touch dummy
Now we only need to create this m2wrapper.sh script.
# note the arguments specified by the maven builder are completely ignored # this also assumes that m2 is correctly installed export JAVA_HOME=/usr/local/lib/j2sdk1.4.2 # tee is just used as a convenience to log the original output and parse it at the same time /usr/local/tools/lib/m2/bin/m2 clean:clean install 2>&1 | tee m2.log | ./parser.sh
The parser script converts the m2 output in something the MavenBuilder will like. The builder searches for lines starting with “BUILD FAILURE” in the output. Maven2 prefixes its output with [INFO] which needs to be stripped out.
#!/usr/bin/perl
while(<stdin>)
{
if ($_ =~ /^[INFO] (.*)/) { print "$1n"}
else { print "$_"; }
}
(Here also, ignore the \” appearing in this code block. They really should be “. It’s wordpress playing tricks with me.)
This works today using CruiseControl’s trunk. Is has several drawbacks. It is platform specific. It is highly fragile. If CruiseControl code or configuration changes or if maven2 command line and/or output changes it may stop working. For that I cannot guarantee that this approach will work in the future (hence the reason I didn’t put it in the official CruiseControl wiki). It’s just a very simple hack.
As a better long term solution, and if there’s interest in using m2 with CruiseControl, just ask. Someone will create a new builder that natively supports it.