Disable sure-fire and execute fail-safe report to run my test cases in a Maven project - maven

In my parent POM I have configured for sure fire report. But in some modules, I need to skip the sure fire report generation and instead I want to run fail-safe plugin to generate the test report.
I have tried like
<properties>
<skipTests>true</skipTests>
<skipFailsafeTests>false</skipFailsafeTests>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.5</version>
<configuration>
<skipTests>${skipFailsafeTests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipExec>${skipTests}</skipExec>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
But still it seems sure-fire report is running. Is there any way to overcome it?

Related

How to exclude a dependency coming from parent in POM file

I am pulling in dependencies from a parent and need most of the dependencies in there.
But I also wish to be able to exclude 2 dependencies entirely. I am not able to edit the parent
thus this needs to be excluded from my POM file. Is this even possible? I've seen examples for overrides and quite a bit of suggestion to fix the parent POM which as mentioned, I can't do at this time.
Using Maven 3.3.x
My POM file
<parent>
<groupId>com.company.stuff</groupId>
<artifactId>our-parent</artifactId>
<version>1.7</version>
</parent>
<!-- other dependencies and build and plugins -->
The parent in above pulls in following plugins which I wish to exclude entirely.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${some.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${some.version}</version>
</plugin>
Is there a way around this? Please advice. Thanks.
Tried with Thiago's suggestion, same outcome.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<executions>
<execution>
<id>maven-checkstyle-plugin</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
Why not just skip the plugin executions?
You could set the skip parameter of both plugins to true.
<plugin>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<executions>
<execution>
<id>ID_AS_IN_PARENT</id> <!-- id is necessary sometimes -->
<phase>none</phase>
</execution>
</executions>
</plugin>

Why "mvn site" is running tests?

I have the following build configuration for a Spring Boot application.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
When I run mvn site, I expect the site goal of the site phase to execute. But my tests are running, which means the test goal of the default lifecycle is also getting executed.
I know I can skip running the test with -DskipTets, but I want to understand why this is happening?

Get Arquillians Code Coverage Using JaCoCo

I have a Maven build that runs Arquillian tests on a Wildfly. What I want to do is run JaCoCo as well so that I get a test coverage.
What I did to my working Arquillian setup: I changed the parent's pom.xml the following way:
<properties>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<jacoco.out.ut.file>../target/jacoco/jacoco-ut.exec</jacoco.out.ut.file>
<jacoco.out.it.file>../target/jacoco/jacoco-it.exec</jacoco.out.it.file>
<sonar.jacoco.reportPaths>${jacoco.out.ut.file},${jacoco.out.it.file}</sonar.jacoco.reportPaths>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-ut-agent</id>
<phase>process-test-classes</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${jacoco.out.ut.file}</destFile>
<propertyName>jacoco.agent.ut.arg</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>prepare-it-agent</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${jacoco.out.it.file}</destFile>
<propertyName>jacoco.agent.it.arg</propertyName>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${test.argLine} ${jacoco.agent.it.arg}</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${test.argLine} ${jacoco.agent.ut.arg}</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
That's a setup that works in multiple other projects (without Arquillian), so I assume it must work now, too.
For the module hosting the integration project I added the following:
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>1.0.0.Alpha9</version>
<scope>test</scope>
</dependency>
</dependencies>
The maven-surefire-plugin is called there (which is weird to me, but I tried maven-failsafe-plugin and it didn't work either).
When executed the module produces a jacoco.exec (which is 70kb for only the one module, so at least not empty). Sonar uses these files in the report generation. Still the code coverage gets displayed as 0%.
I found a couple tutorials on this topic, but they all seem to be missing a step (at least the setup is always identical to mine).
How do I get Arquillian to use JaCoCo to report the code coverage?

maven-surefire-plugin doesn't run parallel tests

I have a project Serenity+Java+JUnit and I try to run my tests in parallel.
I paste this into my pom and after mvn integration-test, it is still run in a chain :(
What I have done wrong?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<parallel>all</parallel>
<forkMode>perthread</forkMode>
<threadCount>4</threadCount>
</configuration>
</plugin>
Have resolved it by adding another plugin instead of surefire-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<forkCount>5</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<databaseSchema>MY_TEST_SCHEMA_5</databaseSchema>
</systemPropertyVariables>
<workingDirectory>FORK_DIRECTORY_5</workingDirectory>
</configuration>
</plugin>
Not really sure if what your answer suggests is correct. You have placed concurrency configuration in Maven Failsafe, a plugin which is responsible for safely terminating the test execution once an exception has occurred therein. Although, as you claim it this has resolved your issue, it might impact your project in the long run.
According to Maven's website, the below code should be placed under Maven Surefire configuration.
<forkCount>5</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
Having followed these guidelines, I was able to successfully run tests in parallel with only updating Surefire plugin.

Multi Module Maven Project Code Coverage Issue on Sonar

I have a question related to multi module maven project with JaCoCo and SONAR.
I have a parent and 3 child modules.
parent |-child1 - pom.xml |-child2 - pom.xml |-child3 - pom.xml |-pom.xml
I include the JaCoCo plugin in the parent pom.xml. When I run the mvn clean install sonar:sonar build from parent pom.xml, I see that each child generates its own jacoco.exec file. Something like this child1/target/jacoco.exec, child2/target/jacoco.exec etc . However, there is no jacoco.exec been generated in the parent level.
When I run my sonar analysis, I see that the unit test coverage is showing up as 0.0% on the sonar dashboard.
My question is
1. What should I do to see the unit test coverage for the entire project?
2. To show the one unit test coverage, Does SONAR pick the jacoco.exec file from the parent level or from the child level?
Please help. This is really a road blocker for me. Appreciate all your inputs.
I was facing the same issue, then I included the following in each module pom xml and it worked:
<!-- Sonar START -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<jacoco.version>0.7.9</jacoco.version>
<!-- Sonar START -->
Plugins :
<!-- SONAR config START -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<tasks>
<echo>Project Base Path (WEB):: ${project.basedir}</echo>
<echo>Jacoco exec target path (WEB):: ${sonar.jacoco.reportPath}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
<!-- SONAR config END -->
And configure in Jenkins for "Goals and options" as:
sonar:sonar
For Running specific tests :
sonar:sonar -DfailIfNoTests=false -Dtest=<Test Class> test
I had the similar issue, 0.0% coverage & no unit tests count on Sonar dashboard with SonarQube 6.7.2:
Maven : 3.5.2,
Java : 1.8,
Jacoco : Worked with 7.0/7.9/8.0,
OS : Windows
After a lot of struggle finding for correct solution, resolved issue with this configuration my parent pom looks like:
<properties>
<!--Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I've tried few other options like jacoco-aggregate & even creating a sub-module by including that in parent pom but nothing really worked & this is simple. I see in logs <sonar.jacoco.reportPath> is deprecated,but still works as is and seems like auto replaced on execution or can be manually updated to <sonar.jacoco.reportPaths> or latest. Once after doing setup in cmd start with mvn clean install then mvn org.jacoco:jacoco-maven-plugin:prepare-agent install & then do mvn sonar:sonar , this is what I've tried please let me know if some other best possible solution available.Hope this helps!! If not please post your question..

Resources