'Extent reports are not generated when running class level tests using -Dtest option from command line

Having a pom based project and successfully able to execute test and generate reports at suite level,group level. But moment I run the test using -Dtest="classname", extent report not get generated.

mvn test -DSuiteFilePath="src/test/resources/suites/testng.xml" -Dtest="classname"

Please help with the solution at earliest.

pom is here:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>RestAssuredAPI</groupId>
  <artifactId>RestAssuredAPI</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>RestAssuredAPI</name>
  <description>RestAssuredAPI</description>
<build>
<!--<plugins>
 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
<configuration>
<includes>*.*</includes>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFiles}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>-->
    <plugins>
        <!-- Compiler plug-in -->
        <!--<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
        </plugin>-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${SuiteFilePath}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>  
  
   <dependencies>

    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
       <!-- <version>3.1.3</version>-->
        <version>5.0.4</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.4.0</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.11</version>
    </dependency>
    <dependency>
   <groupId>com.aventstack</groupId>
   <artifactId>extentreports</artifactId>
   <version>3.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache-extras.beanshell/bsh -->
<dependency>
    <groupId>org.apache-extras.beanshell</groupId>
    <artifactId>bsh</artifactId>
    <version>2.0b6</version>
</dependency>

<dependency>
   <groupId>com.relevantcodes</groupId>
   <artifactId>extentreports</artifactId>
   <version>2.41.2</version>
</dependency>
    
       <!--changes performed on 10th Feb-->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>
       <dependency>
           <groupId>org.apache.poi</groupId>
           <artifactId>poi-ooxml</artifactId>
           <version>3.17</version>
       </dependency>
       <dependency>
           <groupId>org.apache.poi</groupId>
           <artifactId>poi</artifactId>
           <version>3.17</version>
       </dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.13.0</version>
  </dependency>
    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
</dependency>
  <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <version>2.4.0</version>
</dependency>
</dependencies>
 <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source