根据我们上面的对话,听起来您正在寻找一种多合一的 XML -> HTML 转换。我不知道有这样的插件,但我相信与其他一两个插件结合使用的安全报告插件会让你到达你需要的地方。
首先,我会查看usage docs for the surefire-report plugin。此外,我还整理了一个快速示例,说明如何结合使用 surefire、pmd 和 surefire 报告插件:
使用以下项目结构:
├── pom.xml
└── src
├── main
│ ├── java
│ │ ├── Main.java
│ │ └── SomeClass.java
│ └── resources
└── test
└── java
└── SampleTest.java
还有这些类定义:
SomeClass.java
import java.util.List; //Unused import, so PMD will have something to pick up
public class SomeClass {
public void testMethod(){
System.out.println("This is my test method with some PMD violations");
}
}
SampleTest.java
import org.junit.Assert;
import org.junit.Test;
//Sample tests, so the surefire report will have something to show
public class SampleTest {
@Test
public void test1(){
Assert.assertTrue(true);
}
@Test
public void test2(){
Assert.assertTrue(false);
}
}
最后是 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>sample</groupId>
<artifactId>plugins</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</reporting>
</project>
结果是当我运行时
mvn clean pmd:pmd site
然后我可以打开生成的站点:
open target/site/index.html
从那里,我可以看到我生成的报告,在我的例子中,只有 PMD 和 surefire 测试报告:
此外,如果您想获得更多可能无法使用surefire 报告插件的报告,请查看Jacoco,甚至可以查看Sonar。