Hi,
Is there a simple way to send out email notifications in Maven for each build without outside CI tools, just like Ant?
Hi,
Is there a simple way to send out email notifications in Maven for each build without outside CI tools, just like Ant?
I'd strongly recommend using a CI tool to manage this for you, I personally like to configure which emails are to be sent on the build to avoid spamming. For example only notify when the build starts failing, or starts working again, not on every failure.
If you're sure this is the right approach, you can use the maven-changes-plugin to send an email on each build. You can customise the mail template with velocity, and bind the execution of the goals to an appropriate phase so it is sent when you want it.
I'd also put the configuration in a profile so it is sent when you want it to be (i.e. when the profile is active).
The configuration looks something like this:
<profiles>
<profile>
<id>notify</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<executions>
<execution>
<!--send an email in the install phase,
could be changed depending on your needs-->
<phase>install</phase>
<goals>
<goal>announcement-mail</goal>
</goals>
</execution>
</executions>
<configuration>
<smtpHost>mail.yourhost.com</smtpHost>
<smtpPort implementation="java.lang.Integer">25</smtpPort>
<toAddresses>
<toAddress implementation="java.lang.String">
[email protected]</toAddress>
<toAddress implementation="java.lang.String">
[email protected]</toAddress>
</toAddresses>
<!--using a custom velocity template in
src/main/resources/mailTemplate/announcement.vm -->
<template>announcement.vm</template>
<templateDirectory>mailTemplate</templateDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
If CI is not an option I would use a simple script wrapper:
mvn install 2>&1 | tee build.log && cat build.log | mail -s 'Maven build output' [email protected] && rm -f build.log
If you do decide to use a CI tool, I would strongly recommend Hudson. The installation page shows how easy it is to run. Continuous integration server sounds pompous and enterprisey, but Hudson is dead-simple.