My pom.xml has the below properties:
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../target/jacoco.exec</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<surefire.plugin.argline>-XX:PermSize=256m -XX:MaxPermSize=1048m</surefire.plugin.argline>
This is what I have in my Jacoco plugin configuration:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>target/jacoco-report</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<destFile>target/jacoco.exec</destFile>
<dataFile>target/jacoco.exec</dataFile>
<append>true</append>
</configuration>
</plugin>
I'm using Sonar 7.8. I see the jacoco.exec file into the target folder after run:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
However, when I go to the Sonar page, I see how many test I have, but I only see 0% in the test coverage. Any suggestion?
Related
I have a package, com.org.projectname.model, in my project. What I want to do is exclude all the files within this package from SonarQube coverage. I tried,
<exclude>**/model /*.class</exclude> and <exclude>**/com/org/projectname/model/*.class</exclude>, but this didn't work.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
</excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/coverage-data/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/coverage-data/jacoco-ut.exec</dataFile>
<outputDirectory>target/coverage-reports/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
How to fix this issue? Or is there any other way?
Have you tried using sonar.exclusions in your POM properties?
<properties>
<sonar.exclusions>
**/model/*.java
</sonar.exclusions>
</properties>
I am using eirslett frontend-maven-plugin to build war file but getting the below error:
[ERROR] error An unexpected error occurred:
"http://registry.npmjs.org/calendar-utils/-/calendar-utils-0.1.2.tgz:
Request failed \"403 Forbidden\"".
below is the pom.xml for how I used the plugin
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
<nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
<npmDownloadRoot>http://registry.npmjs.org/npm/-/</npmDownloadRoot>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>install --force</arguments>
</configuration>
</execution>
<execution>
<id>webpack build test</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>run webpack:test</arguments>
<yarnInheritsProxyConfigFromMaven>true</yarnInheritsProxyConfigFromMaven>
</configuration>
</execution>
<execution>
<id>webpack build prod</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run webpack:prod</arguments>
<yarnInheritsProxyConfigFromMaven>true</yarnInheritsProxyConfigFromMaven>
</configuration>
</execution>
</executions>
</plugin>
I am having this problem in prod profile only
./mvnw -Pprod package -DskipTests
any pointers are welcome.
I have configured failsafe together with tomcat7-maven-plugin for making integration-test. It's great and works very well when I type:
mvn clean verify -P integration-test
My pom.xml is like that:
<!-- Runs integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/onde-vou</path>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
But I got an unexpected behavior. When I type:
mvn clean install
It starts the tomcat and shutdown at the end of the process.
How do I avoid this behavior? It is useless for me and I lose some secs.
You can try mvn clean install -Dmaven.test.skip=true which skip the test, hence skips the execution pre-integration-test
or remove
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
I'm trying with more than 15 version on jacoco and still is something wrong.
I've tried with different pom.xml files found on internet, but still without any effects.
Below my pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.build</artifactId>
<version>0.6.5.201403032054</version>
<relativePath>../org.jacoco.build</relativePath>
</parent>
<artifactId>jacoco</artifactId>
<packaging>pom</packaging>
<name>JaCoCo :: Distribution</name>
<description>JaCoCo Standalone Distribution</description>
<properties>
<jarsigner.skip>true</jarsigner.skip>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>${argLine} -Xmx2048m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>${argLine} -Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.5.201403032054</version>
<executions>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-integration-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>jacoco-${qualified.bundle.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-distribution-size</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>verify</phase>
<configuration>
<rules>
<requireFilesSize>
<maxsize>2500000</maxsize>
<minsize>2100000</minsize>
<files>
<file>${project.build.directory}/jacoco-${qualified.bundle.version}.zip</file>
</files>
</requireFilesSize>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And the output:
[ERROR] Failed to execute goal org.jacoco:jacoco-maven- plugin:0.6.5.201403032054:check (default-cli) on project jacoco: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.6.5.201403032054:check are missing or invalid -> [Help 1]
And the output depends of version jacoco.
Do you have any ideas?
I suspect you are running a specific goal of jacoco (the check goal to be specific), meaning you are not running any specific phase of any lifecycle.
Like:
mvn jacoco:check
Note that your execution enforce-distribution-size is bound to the verify phase of the default lifecycle - so, if you want the execution enforce-distribution-size to occur, you should either:
run with a phase that is at least verify (I assume you don't want to do this) or
rename the <id> of that <execution> to default-cli (see this), if you require a maven run with specific jacoco goal to work, say the check goal. Like, change the following line:
<id>enforce-distribution-size</id>
to
<id>default-cli</id>
That's all you'll need to do.
I'm trying to get pre and post integration phase to work with maven, to no avail.
My goal is to set up and tear down integration tests by running some binaries that are necessary. I'm testing with antrun-plugin and exec-plugin, but none of them prints the messages.
I'm running mvn verify. If I bind the plugins to clean phase and run mvn clean, the echo message and the ls are shown.
What's wrong? I'm using maven3
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>ls</executable>
<arguments>
<argument>-la</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>xxx</id>
<configuration>
<target>
<echo>Cleaning deployed website</echo>
</target>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I helped someone else get the failsafe plugin configured correctly earlier. Try explicitly specifying the phases in the failsafe plugin executions. Not sure why that is needed, as the failsafe plugin docs say the goals are supposed to be bound to correct phases by default - but it seems to be.