如何发送Maven构建的电子邮件通知

时间:2009-08-07 07:02:00

标签: java maven-2 build notifications

是否有一种简单的方法可以在没有外部CI工具的情况下在Maven中为每个构建发送电子邮件通知,就像Ant一样?

5 个答案:

答案 0 :(得分:4)

如果CI不是一个选项,我会使用一个简单的脚本包装器:

mvn install 2>&1 | tee build.log && cat build.log | mail -s 'Maven build output' user@example.com && rm -f build.log

如果您决定使用CI工具,我强烈推荐Hudson。 installation page显示了运行的简便程度。 持续集成服务器听起来华而不实,但是Hudson很简单。

答案 1 :(得分:2)

我强烈建议您使用CI工具为您管理,我个人喜欢配置要在构建中发送哪些电子邮件以避免发送垃圾邮件。例如,仅在构建开始失败时通知,或者再次开始工作,而不是在每次失败时通知。

如果您确定这是正确的方法,则可以使用maven-changes-plugin在每个版本上发送电子邮件。您可以customise the mail template with velocity,并将目标的执行绑定到适当的阶段,以便在您需要时发送。

我还将配置放在配置文件中,以便在您希望它时发送(即当配置文件处于活动状态时)。

配置如下所示:

<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">
                someones@email.com</toAddress>
              <toAddress implementation="java.lang.String">
                 someoneelse@email.com</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>

答案 2 :(得分:1)

虽然这个问题有点老了,但可能有人仍然需要一个不同的解决方案:我已经为此目的创建了一个插件。看看plugin's page at github.com。 多部分替代MimeMessages没有实现(看看FAQ的原因),以及一个体面的模板,但只要你只是想发送带附件的文本邮件它应该做的伎俩

我计划将它提交给mojo.codehaus.org,因此gId。现在,您必须自己编译 - 抱歉给您带来不便。

答案 3 :(得分:1)

还有一个高度可自定义的Postman mail plugin,它为您提供发送测试结果的选项,甚至是指定源文件的任意html。 Here's一个很好的线程,解释了如何配置它。

答案 4 :(得分:0)

我不使用Maven,但我认为您可以使用plugin来完成此操作。