Reputation: 483
Is there a simple way to send out email notifications in Maven for each build without outside CI tools, just like Ant?
Upvotes: 5
Views: 11480
Reputation: 3293
There is also a highly customizable Postman mail plugin which gives you options to send test results or even an arbitrary html specifying a source file. Here's a good thread explaining how it should be configured.
Upvotes: 1
Reputation: 20703
Though the question is a bit older, it might be possible that someone still needs a different solution: I have created a plugin for just that purpose. Have a look at the plugin's page at github.com. Multipart-alternative MimeMessages aren't implemented (have a look at the FAQ for the reasons), as well as a decent templating, but as long as you simply want to send a text mail with attachements it should do the trick.
I plan to submit it to mojo.codehaus.org, hence the gId. For now, you have to compile it yourself - sorry for that inconvenience.
Upvotes: 1
Reputation: 68308
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.
Upvotes: 4
Reputation: 84058
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>
Upvotes: 4
Reputation: 70230
I don't use Maven, but I think you can do this with a plugin.
Upvotes: 0