I am trying to get project with submodules to test and generate reports correctly, but have got some problems.
I have the following project structure:
parent
|-test1
|-test2
and the pom.xml for parent
looks like this:
<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>
And I use mvn clean install site
to build the project, run the tests and generate a site (which uses maven site plugin, which in turn uses maven surefire report plugin, to generate test report).
The trouble is the parent pom.xml is executed with all phases (clean, install and site) before submodules' pom.xml are executed, hence no test report from test1
and test2
are aggregated in parent
.
So is there a way to execute mvn clean install site
in a single line, or do I absolutely have to execute mvn clean install
first then mvn site
?
Thanks for any suggestions.