我试图获取包含子模块的项目以正确地测试和生成报告,但是遇到了一些问题。
我的项目结构如下:
parent
|-test1
|-test2
而parent
的pom.xml文件看起来像这样:
<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>parent</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>test1</module>
<module>test2</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<aggregate>true</aggregate>
<reportsDirectories>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
</reportsDirectories>
</configuration>
<reportSets>
<reportSet>
<inherited>false</inherited>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
我使用mvn clean install site
命令构建项目、运行测试并生成网站(使用maven站点插件,该插件又使用maven surefire报告插件生成测试报告)。
问题在于父Pom.xml文件在所有阶段(clean、install和site)执行之前先执行子模块的Pom.xml文件,因此parent
中聚合的test1
和test2
测试报告为空。
因此,是否有一种方法可以在单个命令行中执行mvn clean install site
,或者必须先执行mvn clean install
,然后再执行mvn site
?
感谢任何建议。
parent
还是root
或config
?这真的重要吗?) - isnot2bad