I have added cucumber report plugin in pom.xml as follows:
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven.cucumber.reporting.version}</version>
<executions>
<execution>
<id>execution</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<outputDirectory>${project.build.directory}/cucumber-html-reports</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
which will generate reports only if there is no failure, but to generate report even after failure I had to add:
<testFailureIgnore>true</testFailureIgnore>
in the maven surefire plugin, this is generation report even after failure in test but problem is BUILD SUCCESS message generated and it should be BUILD FAILURE.
any idea?
Related
I have project with Mockito and TestNG tests. I want to see coverage in Sonarqube. For this I should have jacoco.exec file. When I try to build my project, in result I have "BUILD SUCCESS" without jacoco.exec file in target folder.
There is part of my pom.xml file.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report-aggregate</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
...
command to start build:
mvn clean install sonar:sonar -Dsonar.projectKey=number20 -Dsonar.host.url=http://localhost:9000 -Dsonar.login=**mylogin**
Your configuration hasn't the report execution goal and in addition to this you should not use jacoco exec file because it's deprecated. You should configure the sonar jacoco plugin as suggested in this official example.
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And then jacoco report, generated in the default path, will be imported by sonar.
We have a multi-module maven project. We are using java8.
-Parent
-- Child 1
-- Child 2
-- Coverage-Report
All projects have unit test cases, those all are working good and have more than 85% of coverage. Parent pom.xml file has jacoco-profile and jacoco-maven-plugin plugin as below
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<destFile>${sonar.coverage.jacoco.xmlReportPaths}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
In Coverage-Report module, there is only pom.xml which is for aggregating report. It has profile as jacoco as below
<profile>
<id>jacoco</id>
<activation/>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
To generate the report, we are using below command
mvn clean verify -Pjacoco
We do see the file getting generated which is mentioned in parent pom.xml
<sonar.coverage.jacoco.xmlReportPaths>${maven.multiModuleProjectDirectory}/ocapi-promotion-service-coverage-report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
However this file, jacoco.xml, is not proper XML. It has some encoded character as below. (few lines from that file)
��ca6191af5ae0-1a24a201}-�Sy}-ƌ|pW�\����;org/springframework/context/annotation/BeanAnnotationHelper�w~�j�zI�ZMorg/springframework/boot/autoconfigure/condition/FilteringSpringBootCondition������e֢+org/sp
On jenkins we see below error
Caused by: java.nio.charset.MalformedInputException: Input length = 1
I have followed an article from sonar source community https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151 which gives some steps. But I am not able to generate XML file. Please help.
I got the following plugin in my pom.xml but the maven-cucmber-reporting pluging is unable to generate the report. Also it shows "Plugin could not be resolved. Ensure the plugins groupid,artifactid and version are present.
Could someone help me resolving this issue? or is the maven-cucumber-reporting jar is unavailable?
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>CucumberWebGui</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
I just added Jacoco on my maven dependencies to run integration tests. Then, I created an integration test to test my controller. For example, I tested my HTTP response codes, the headers and the response resources. After that, I created a profile on maven that starts an embedded tomcat. So, everytime I want to run my integration tests, I just put the profile on the maven goals. However, when I execute the build on Jenkins and Sonar reads the reports from Jacoco, the reports says that I have not tested my controller. The question is: How I tell Jacoco that I have passed through my Controllers, Services and Repositories?
Thanks to all!
Are you getting any Integration Coverage, or just 0%?
It can be quite tricky to set up Integration Test Coverage using maven and Sonar.
Check there is a jacoco file produced when the IT tests are run.
Check your POM set up compared to this...
<properties>
<!-- Jacoco Properties -->
<jacoco.version>0.7.4.201502262128</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.itReportPath>${project.basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.language>java</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-unit-test-agent</id>
<configuration>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>prepare-it-test-agent</id>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Link to GitHub example
BeyondCoding.net
In my maven project I use the pgp plugin to sign my jars. I need to do this only when deploying to remote repo, but not when installing to local repo. So I tried to set the phase to deploy.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
With that configuration maven first deploys to remote repo and theh signs my jars...
I read that plugins are executed in the order they are defined in POM file, so I tried to configure deploy-plugin after sign plugin, but that didnt have any effect
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
How can I achieve that sign plugin is not executed on install, but on deploy before artifacts are uploaded? I'm using maven3.
First i would suggest to update maven-gpg-plugin to an more up-to-date version cause this version 1.1 is of 2010..Apart from that i would suggest to keep the defaults of the plugins which means the binding of maven-deploy-plugin as the deploy life cycle and for the maven-gpg-plugin the verify life cycle phase which is not ideal if you have integration tests. In such cases it makes sense to define a profile which is activated only in release cases to prevent confusions with integration test.
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
I have seen project putting the gpg-plugin in verify phase.
May I know what version of Maven you are using? I believe the plugin in same phase should run in order it is defined, after Maven 2.0.10 (or probably earlier). However as maven-deploy-plugin is default binding for deploy phase, I am not clear if the ordering will be in effect