Share

November 25, 2008

Maven 2 - maven-changes-plugin - with email notification and changes.xml validation

One very usefull feature of Maven is that when you release your project a notification can be sent out to the Dev/QA teams and a changes.html page can be created in the maven site.
The following is how to do that

1. Add the following plugin to pom.xml

1.1 Setup from and to emails

<properties>
   <releaseEmail.from.name>Release Mailler</releaseEmail.from.name>
   <releaseEmail.from.email>app-release@company.com</releaseEmail.from.email>      
   <releaseEmail.to.email1>dev-team@company.com</releaseEmail.to.email1>   
   <releaseEmail.to.email2>qa-team@company.com </releaseEmail.to.email2></properties>

1.2 Add the plugin

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-changes-plugin</artifactId>
  <executions>
  <execution>
   <phase>deploy</phase>
       <goals>
    <goal>announcement-generate</goal>
       </goals>
   <id>announcement-generate</id>
  </execution>
  <execution>
       <phase>deploy</phase>
       <goals>
    <goal>announcement-mail</goal>
       </goals>
       <id>announcement-mail</id>
  </execution>
 </executions>
  <configuration>
  <smtpHost>mailone.real.com</smtpHost>
  <smtpPort implementation="java.lang.Integer">25</smtpPort>
  <mailSender>
       <name>${releaseEmail.from.name}</name>
       <email>${releaseEmail.from.email}</email>
  </mailSender>
  <toAddresses>
       <toAddress implementation="java.lang.String">${releaseEmail.to.email1}</toAddress>
       <toAddress implementation="java.lang.String">${releaseEmail.to.email2}</toAddress>
  </toAddresses>
  <developmentTeam>MyCompany.com Team</developmentTeam>
  <urlDownload>http://mavenrepo.company.com/repository/com/copmany/${project.artifactId}/${project.version}/</urlDownload>
  <introduction> This is a notification email that the ${project.version} build of ${project.name} has been code reviewed and deployed to Repository. Change list can be viewed on ${project.url}/changes-report.html</introduction>
  </configuration>
</plugin>

2. Create a changes.xml in /src/changes/changes.xml

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/changes/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd">
    <properties>
        <title>Change Log for My App</title>
    </properties>
    <body>
        <release version="1.0.1" description="1st release" date="11/11/08">
            <action dev="gdawoud" issue="12344" type="fix">Add a fix for bug</action>
        </release>
        <release version="1.0" description="1st release" date="11/11/08">
            <action dev="gdawoud" issue="12344" type="fix">Add a fix for bug</action>
        </release>        
    </body>
</document>


And that is it.

Note: The changes plugin has an issue where if the changes.xml does not include an entry for a release matching the build release version, the build will fail after deploying the war/jar/etc to the maven repository. To Fix that you will have to check in an updated changes.xml with a matching release and retag it with the release tag then call cvs update and mvn release:prepare again

Check out the follow up blog