如何在测试后在 maven 中将 Java 类作为目标运行



我创建了一个Java类来通过电子邮件发送报告。报告由Maven Surfire插件生成。 现在我有一个问题是测试报告在项目完成运行之前不会保存。因此,如果我在@AfterSuite中调用该java类,它将失败。

有没有办法在 maven 目标之后运行 java 类?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SoapOCPAutomation</groupId>
<artifactId>SoapOCPAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SoapOCPAutomation</name>
<description>SoapOCPAutomation</description><repositories>
<repository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<forkCount>0</forkCount>
<suiteXmlFiles>         
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>send-report</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.acxsys.ocp.api.emt.ks.report.KSSendEmail</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

您可以将 maven-exec 插件与 java 目标一起使用:

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>send-report</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>your.reporting.Class</mainClass>
</configuration>
</plugin>
</plugins>
</build>

当您执行mvn packagemvn install时,这将在package阶段执行您的报告类,该阶段是在万无一失的插件执行之后。

最新更新