sonar, jacoco, and maven are not cooperating for me - maven-3

Maven 3.0.4
sonar-maven-plugin 2.2
jacoco-maven-plugin 0.6.4.201312101107
When I run mvn sonar:sonar, the prepare-agent goal of the jacoco-maven-plugin fails to run, so the agent arguments aren't there for surefire when needed.
When I explicitly run mvn prepare-package sonar:sonar, I get an infinite recursion in jacoco initialization.
Apparently I'm missing something, but what?
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jaCoCoSurefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

You have to configure plenty things to make jacoco works. Check that configuration:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<executions>
<!-- prepare agent for measuring unit tests -->
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
</configuration>
</execution>
</executions>
</plugin>
Also you can refer to my blog post dealing with multimodule projects with unit and integration tests: http://www.kubrynski.com/2013/03/measuring-overall-code-coverage-in.html

Related

Jacoco maven plugin prepare-agent goal getting added twice

Tools :
Maven 3.2
Maven Jacoco Plugin - version 0.5.5.201112152213
Issue :
Below is the jacoco pugin included in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<configuration>
<destFile>${basedir}/target/reports/jacoco.exec</destFile>
<dataFile>${basedir}/target/reports/jacoco.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
After running effective-pom , I am getting below output -
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
</executions>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</plugin>
It seems that prepare-agent goal has been included twice . The redundant goal is
<id>agent</id> which is not present in pom.xml file and haven't been added.
So , my question is : why is this goal getting included in pom even though the goal is already configured explicitly with id <id>jacoco-initialize</id>.
EDIT :
Further digging deep into problem , I removed the plugin (jacoco-maven-plugin) altogether from child module and when I run mvn help:effective-pom , interestingly it is still showing jacoco-maven-plugin with only one goal in it as below . It is the same one which gets added additionally. That means parent module is adding this plugin . But there is no reference of this plugin in parent module
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>

Analyzed bundle 'dump' with 0 classes

In the current configuration, I am using a jacoco-agent in the tcpserver mode for web application deployed on the serve node. Also, using jacoco-maven plugin to generate dump and report from my local node. I am able to get the dump in my local node by task mvn jacoco:dump. But when trying to generate the report against dump file by task mvn jacoco:report, getting "Analyzed bundle 'dump' with 0 classes".
Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<address>*.*.*.*</address>
<destFile>/app/jacoco_agent/new.exec</destFile>
<port>7906</port>
<reset>true</reset>
<append>false</append>
</configuration>
<executions>
<execution>
<phase>post-integration-test</phase>
<goals>
<goal>dump</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>/app/jacoco_agent/new.exec</dataFile>
<outputDirectory>/app/jacoco_agent/jacoco-ut</outputDirectory>
<includes>/target/classes</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can I generate a report by using jacoco-maven plugin?
Successfully able to generate a report by jacococli.jar.
java -jar ~/Downloads/jacoco-0.7.10-20171007.201717-57/lib/jacococli.jar report /app/jacoco_agent/new.exec --classfiles /target/classes --html report
Please help me to understand what's wrong, I am doing here with jacoco-maven plugin configuration?
Thanks

m2 release plugin couldn't recognize assembly file with parameterized name

In my POM.xml file, I am using assembly plug in. I want the build to assemble things based on the assembly file, whose name is parametrized. The build works fine. However, if I use m2 release plug in using perform release action in jenkins, the release plugin could not substitute the value for $env and pick up the assembly.xml file. I get the following exception.
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: Error locating assembly descriptor: src/main/assembly/${env}.xml
I have attached the log and POM file.
POM file build portion:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuraenter code heretion>
<descriptors>
<descriptor>src/main/assembly/${env}.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

maven doesn't recognize tests dependencies in additional test-source directories

I'm trying to separate unit tests and integration tests in the same project. I used the build-helper-maven-plugin to configure my additional sources folders ( for integration tests) as below:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<sources>
<source>${integrationSourceDirectory}</source>
</sources>
<resources>
<resource>
<directory>${integrationResourceDirectory}</directory>
<targetPath>${integrationOutputDirectory}</targetPath>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
</execution>
<execution>
<id>add-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
</execution>
</executions>
</plugin>
When I open the project in netbeans 7.3.1. the additional source folder is recognized as "generated sources" and my test libraries are not included in the classpath of the classes indluded in this tests folder (ex. arquillian ).
How can I fix that in netbeans ?
Thanks in advance for your help

How to have a pom.xml but prevent Maven being used for building?

I have a project for which I have created a pom.xml. However, I'm not using Maven as my build system, I am using something else (e.g. ANT). But I want the pom.xml to exist for the use of other tools, e.g. IDEs. How can I make sure, that if someone downloads my project and tries to build it with Maven, they will get a clear indication that they are doing the wrong thing?
Add the following to pom.xml:
<properties>
<maven.build.not.supported>
Do not use Maven to build this module. Please see README.html for
instructions on how to build it.
</maven.build.not.supported>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>fail-clean-lifecycle</id>
<phase>pre-clean</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-default-lifecycle</id>
<phase>validate</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-site-lifecycle</id>
<phase>pre-site</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since we cannot apparently bind a plugin execution to multiple phases, we need to repeat the execution block three times, one for each of the built-in lifecycles (clean, default and site). To avoid duplication of the failure message, we store it in a Maven property and reuse that property in each execution. In each execution we bind to the first phase of the lifecycle to fail it immediately.

Resources