Maven skip generating reports when executing Maven build - maven

I have several reporting plugins defined in the project and when I do Maven → build fails with FileNotFoundException as the reports are cleared when I do Maven → clean. Is there a way to ignore reports when doing Maven build so that build passes without any issue? I tried using Surefire plugin but not luck.
My pom.xml looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>${maven-site-plugin.skip}</skip>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</reporting>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.2.0</version>
</dependency>

For maven-surefire
add after version
<configuration>
<skipTests>true</skipTests>
</configuration>

I got the fix for this now. I updated selenium version to 3.14 and I see no issue when building the project

Related

SpotBugs site report inconsistent with spotbugs:gui goal

I have set up SpotBugs to help us adhere to some standards, but I get different results in my generated site compared to SpotBugs user interface. This is my configuration of SpotBugs in my pom file:
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>
src/test/resources/SpotBugsExcludeFilter.xml
</excludeFilterFile>
</configuration>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>
src/test/resources/SpotBugsExcludeFilter.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
When I run mvn clean install site, the site reports 5 bugs.
When I run mvn clean install spotbugs:gui, the gui reports 0 bugs.
How come there is a difference? It seems as if the site goal disregards my exclusion filter, but I can't see why. I am also not entirely sure how the build/plugins section correlates with the reporting/plugins section. If someone could tell me what I'm messing up here I'd be very grateful.
spotbugs:gui is not triggering the reporting scope where your configuration is defined.
You should be specifying your SpotBugs configuration in the <build> section.
<build>
<plugins>
[...]
<!-- SpotBugs Static Analysis -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>src/test/resources/SpotBugsExcludeFilter.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>
https://github.com/find-sec-bugs/find-sec-bugs/wiki/Maven-configuration

Running "mvn test site" giving [ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project

I'm trying to generate xslt report using reporty-ng with Testng+maven but getting error as
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project Selenium Project: failed to get report for org.reportyng:reporty-ng: Plugin org.reportyng:reporty-ng:1.2 or one of its dependencies could not be resolved: Failure to find org.reportyng:reporty-ng:jar:1.2 in https://github.com/cosminaru/reporty-ng/raw/master/dist/maven was cached in the local repository, resolution will not be reattempted until the update interval of reporty-ng has elapsed or updates are forced -> [Help 1]
Below is the part of the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<!-- TestNG-xslt related configuration. -->
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.2</version>
<configuration>
<!-- Output directory for the testng xslt report -->
<outputDir>/target/testng-xslt-report</outputDir>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
</plugins>
</reporting>
<pluginRepositories>
<pluginRepository>
<id>reporty-ng</id>
<url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
</pluginRepository>
</pluginRepositories>
In my understanding of this, if you run "mvn clean verify", that will include the "site" phase of the build as well as the tests. You shouldn't need to explicitly call the site phase and so don't do it. Also, if you were to explicitly call the "site" phase, you should probably include the site plugin as a dependency, don't you think?
In my experience with both TestNG reports and ReportNG reports, the site plugin is not related to the report output. The site plugin is only related to the "Surefire" (or Failsafe) plugins reporting phase output. In other words, you will notice that the default output folder of Surefire plugin is directly related to the standard output location of "site" plugin, in general. This can be very confusing, I agree.
Also, I would configure it (possibly) like so:
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.4</version>
<configuration>
<outputDirectory>${project.build.directory}/surefire/reportng</outputDirectory>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>${basedir}/target/site</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.9</version>
<configuration>
<outputDirectory>${basedir}/target/site</outputDirectory>
<reportsDirectories>
<reportsDirectories>${basedir}/target/surefire</reportsDirectories>
</reportsDirectories>
</configuration>
<reportSets>
<reportSet>
<id>integration-tests</id>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>

No forking observed with surefire 2.16 despite forkCount being > 1

Here is my setting:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx256m</argLine>
</configuration>
</plugin>
And I'm using junit 4.12:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
But when launching my tests I can't see any forking going on?
I'm using maven 3.2.5 on linux with JDK 8.
I ran a little debug (mvn -X test) and it turns out that despite using version 4.12 surefire isn't using the junit47 provider, but the junit4 provider. Unfortunately the junit4 provider does not seem to handle forkCount.
Crawling through the documentation I could find the following algo that selects the provider : https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
The parallel attribute must be set in order to activate the junit47 provider (a little counter-intuitive...).
I've created a JIRA for that: https://issues.apache.org/jira/browse/SUREFIRE-1171
Now my config looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>1</threadCount>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx256m</argLine>
</configuration>
</plugin>
Edit
Turns out, redirectTestOutputToFile is now rendered useless... I've added a comment to an existing issue : https://issues.apache.org/jira/browse/SUREFIRE-703?focusedCommentId=14653289&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14653289
I came up with the following to have both forks and redirectTestOutputToFile work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<configuration>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx512m</argLine>
</configuration>
</plugin>

Maven complete surefire-report including passed tests logging events

I want to generate a report using surefire-report plugin of maven which will give me a detailed report of all the tests that ran with the log events that were logged during each test run instead of just the events where my test failed. This will also give me the full context where my test failed.
Here is my pom.xml file:
<artifactId>SampleTests</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>sampleTests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.11</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<testSourceDirectory>src/main/test</testSourceDirectory>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<includes>
<include>com/mypackage/**</include>
</includes>
<test>**/*Tests</test>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
And i use mvn surefire-report:report to generate the report here.
So I want to know if there is anything additional that i can do so as to see a detailed report of what happened during the tests run?
As a reference from the maven site
surefire-report:report Generates the test results report into HTML format.
surefire-report:report-only This goal does not run the tests, it only builds the reports.
You are trying the report-only. Try the other one report as a goal
I ended up using ant to get to what I needed. Thanks to this blog: http://blog.varunin.com/2010/03/ant-script-for-generating-junit-report.html#comment-form
If you want to get a detailed report of all the test events then please use this

Unable to force newer version of surefire-plugin in Maven

I have a maven project and I am using the surefire-plugin to run my tests.
Previously, I didn't force any version and maven picked up the 2.4.3 for me (why ??).
I want to use 2.7.2 instead, which has better support for JUnit4 (especially Parametrized tests).
Hence, I have modified the root parent POM like this :
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
However, in the child modules, this is surefire:2.4.3 that keeps being called.
Here is the -X debug trace :
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test'
Whereas in the parent pom, 2.7.2 is used:
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test'
And even the effective-pom shows that the "version" of the plugin if not inherited in child modules:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
Any help would be much appreciated.
Regards,
Raphael

Resources