Search code examples
mavenreportingmaven-surefire-plugin

Maven surefire. Adding timestamp to folder with reports


I'm sure that such a question is already somewhere in internet, but I can't find it so..

I use maven-surefire-plugin. It generates surefire-reports folder with reports in it. I want to have different folders for each run. I'm trying to add timestamp in report name like this:

Pom part:

<properties>
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>

<build>
    <resources>
        <resource>
            <directory>src/test/resources</directory>
        </resource>
    </resources>
    <sourceDirectory>src/main/java</sourceDirectory>

    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</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.16</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <reportsDirectory>${project.build.directory}_${timestamp}</reportsDirectory>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

But in this case I have no surefire-reports folder at all. Somewhere is a mistake but I have no idea where. Can someone give me a clue about this?


Solution

  • That date format is not a valid directory name (especially for the the : char), maybe something like yyyy-MM-dd_HH-mm? also I would go to the target folder:

    <properties>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy-MM-dd_HH-mm</maven.build.timestamp.format>
        <sureFireDir>${project.basedir}/target/${timestamp}</sureFireDir>
    </properties>
    

    ...

    <reportsDirectory>${sureFireDir}</reportsDirectory>