Jacoco Report are not generated in the site - maven

Jacoco reports are not generated when mvn builds the site.
Jacoco reports are generated in my target folder at target\site\jacoco , but somehow I am not able to see "Jacoco Tests" option under "Project Reports" when I try to build the jar site
The only thing I see in the log while generating the site is as below :
[INFO] <<< clirr-maven-plugin:2.6.1:clirr # data-binding <<<
[INFO] configuring report plugin com.cerner.engineering:maven-cerner-ml-dependency-plugin:1.1.1
[INFO] configuring report plugin org.jacoco:jacoco-maven-plugin:0.7.4.201502262128
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\MSVCWorkspace\br-hla-april-data-binding\target\jacoco.exec
I am using the command mvn clean install site
This is how I have configure jacoco in my pom.xml in my build section :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*Suite*.java</exclude>
</excludes>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-Xms64m -Xmx512m -XX:MaxPermSize=256M -enableassertions -XX:+HeapDumpOnOutOfMemoryError ${jacoco.argLine}</argLine>
<junitArtifactName>junit:junit-dep</junitArtifactName>
</configuration>
</plugin>
Jacoco plugin is called like :
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.argLine</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
I am not sure what is causing this issue , not to generate Jacoco reports on my site.
Although I am able to see the below in my logs
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:prepare-agent (default-cli) # data-binding ---
[INFO] argLine set to -javaagent:C:\\_repository\\org\\jacoco\\org.jacoco.agent\\0.7.4.201502262128\\org.jacoco.agent-0.7.4.201502262128-runtime.jar=destfile=C:\\target\\coverage-reports\\jacoco-unit.exec
Thanks !!!

I was able to fix by calling plugin as below
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.argLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>

Related

How to skip the build of jar file "app-source.jar" when maven build happens in SpringBoot?

I have following jar's when in run mvn clean package command
app.jar
app-source.jar
app.jar.original
I dont want the app-source.jar to be generated when I run the above maven command.
I have added
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<finalName>app</finalName>
<addResources>false</addResources>
<arguments>-Dmaven.source.skip=true</arguments>
<includeSystemScope>false</includeSystemScope>
</configuration>
<executions>
<!--<execution>
<id>skip-sources</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
The below specified attribute 'attach' will disable the sources.jar not included in the artifact list
<attach>false</attach>
</configuration>
</execution>-->
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<!--The below specified attribute 'attach' will disable the sources.jar not included in the artifact list-->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
SprinBoot Version : 2.7.5
Maven Source Plugin version : 3.2.0
The goal executed in maven build
[INFO] --- maven-source-plugin:3.2.0:jar-no-fork (attach-sources) # app
[INFO] Building jar: path\to\project\target\app-sources.jar
Thanks
Rohit

How to generate Jacoco integration test report using offline instrumentation?

Build tool: Maven
Reason to use offline instrumentation: Removing Powermock is not an option
Problem:
Both failsafe and surefire are run and reports are generated. However, jacoco.exec is generate but jacoco-it.exec is not. Apart from IT , offline instrumentation, coverage and reporting works fine.
This is the maven plugin configuration I use:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
To run the test i use maven clean install.
At the end of the test execution I get the following output:
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:integration-test (integration-tests) # elune ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:report (default-report) # elune ---
[INFO] Loading execution data file C:\Projects\elune\target\jacoco.exec
[INFO] Analyzed bundle 'elune' with 4 classes
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:report-integration (default-report-integration) # elune ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Another possible pointer might be that the de-instrumentation of the classes happens after the unit tests are run but before the integration tests. But I don't know if this is right or wrong:
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:restore-instrumented-classes (default-restore-instrumented-classes) # elune ---
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) # elune ---
[INFO] Building jar: C:\Projects\elune\target\elune-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) # elune ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:integration-test (default) # elune ---
[INFO] Failsafe report directory: C:\Projects\elune\target\failsafe-reports
Any idea why the jacoco-it.exec is not showing up?
I think the instrumentation of Integration Tests with the failsafe plugin are just not baked in. The restore-instrumented-classes goal defaults to the prepare-package phase which runs before the integration test phase: http://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html - so it may be enough to move that goal into the post-integration-test phase:
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
that may be enough. Otherwise you may be able to change the includes pattern of the surefire plugin to also include the integration tests (if that seems suitable in your case).
#rhinoceros.xn this is the plugin configuration that did the trick for me. But I use mvn clean install to run this
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
The jacoco-it.exec is not showing up after I set the phrase.
command line is:
mvn clean install -Djacoco.version=0.7.8 -DfailOnError=false -Dmaven.test.failure.ignore=true
I finally found the problem was that I didn't add configuration jacoco-agent.destfile in maven-failsafe-plugin.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco-it.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

Maven: ant-run plugin echo does not seem to execute

I have a maven project that is using the ant-run plugin. I added an echo message but it does not seem to execute:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ast-application-deployment-kit</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="Starting ant-run target configuration."/>
But when I mvn clean package, I see this
[INFO] --- maven-antrun-plugin:1.3:run (my-app) # my-app ---
[INFO] Executing tasks
[INFO] Executed tasks
But I do not see the echo. What am I doing wrong?
Consider upgrading your plugin version to the latest (1.8):
This POM snippet prints echo:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo>NOW YOU CAN SEE ME!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

All maven flyway plugins are executed with the last user

I have two oracle users and I am creating different schema for them. I mean each schema has different tables, types etc.
I wanted to create both schemas by flyway maven plugin, first I had two maven plugins, but then I tried also to have two separate profiles:
<profiles>
<profile>
<id>database</id>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<configuration>
<url>jdbc:oracle:thin:#devdb2:1521:ZOOMUTF</url>
<table>SCHEMA_UPDATES</table>
<outOfOrder>true</outOfOrder>
<locations>
<location>db/callrec</location>
</locations>
<user>cr_5199_mensik_mvn</user>
<password>callrec</password>
<serverId>callrec</serverId>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>database_wbsc</id>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<configuration>
<url>jdbc:oracle:thin:#devdb2:1521:ZOOMUTF</url>
<table>SCHEMA_UPDATES</table>
<outOfOrder>true</outOfOrder>
<locations>
<location>db/wbsc</location>
</locations>
<user>sc_5199_mensik_mvn</user>
<password>wbsc</password>
<serverId>wbsc</serverId>
</configuration>
<executions>
<execution>
<id>wbsc_compile</id>
<phase>compile</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
<execution>
<id>wbsc_clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Then I execute:
mvn clean -Pdatabase,database_wbsc
But result is that only second profile is executed twice:
[INFO] [clean:clean {execution: default-clean}]
[INFO] [flyway:clean {execution: clean}]
[INFO] Cleaned schema "sc_5199_mensik_mvn" (execution time 00:00.023s)
[INFO] [flyway:clean {execution: wbsc_clean}]
[INFO] Cleaned schema "sc_5199_mensik_mvn" (execution time 00:00.018s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
If I switch order of profiles in xml (not in maven execution command) then the second user is used.
How can I execute both profiles but with their configuration?
try providing the configuration at the execution level rather than the plugin level.
<plugin>
<executions>
<execution>
<id>execution1</id>
<configuration>
</configuration>
</execution>
<execution>
<id>execution2</id>
<configuration>
</configuration>
</execution>
</executions>
</plugin>

how to deploy web app to jetty

I have an web app(actually a gwt app), and i want to deploy it to Jetty server for selenium testing, i used maven, maven-jetty-plugin, gwt-maven-plugin and selenium-maven-plugin, i finally got jetty and selenium sever running but the selenium tests fail because of the famous 404 eror:
com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://127.0.0.1:8080/index.html Response_Code = 404 Error_Message = Not Found
i m not sure if my jetty configuration is correct since i m kind of new to it, here is it(maven-jetty-plugin):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/sample-console</contextPath>
<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integraion-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
when i ran mvn clean install, i can see the output from command window:
[INFO] Configuring Jetty for project: DYI sample Console
[INFO] Webapp source directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Reload Mechanic: automatic
[INFO] Classes = /Users/dyi/Documents/workspace/sample/console/target/classes
log4j:WARN No appenders could be found for logger (org.mortbay.log).
log4j:WARN Please initialize the log4j system properly.
[INFO] Context path = /sample-console
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT/WEB-INF/web.xml
[INFO] Webapp directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Starting jetty 6.1.22 ...
[INFO] Started Jetty Server
[INFO] [selenium:start-server {execution: start}]
and my folder structure looks like this:
--sample/
-- console/
-- src/
-- target/
-- classes/
-- sample-console-0.1-SNAPSHOT/
-- css/
-- images/
-- img/
-- index.html
-- js/
-- META-INF/
-- security/
-- test.html
-- WEB-INF/
-- classes/
-- lib/
-- web.xml
the thing i don't understand is i can see the index.html page is right there in the folder 'sample-console-0.1-SNAPSHOT', why it cannot find it? is that because i set the 'contextPath' wrong? i tried setting it to '/', then i got 503 service not available error. anyone can help? much thanks!!
It sounds like you're trying to run the app out of the webapp directory, which won't work in a GWT app. Try setting the goal in your jetty maven plugin to be run-war instead of run, like this:
<modelVersion>4.0.0</modelVersion>
<groupId>org.proj.web</groupId>
<artifactId>gwtapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>gwtapp</name>
<properties>
...
</properties>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<excludes>
<exclude>**/integration/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/integration/**
</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<!-- Selenium and integration testing support -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<webAppConfig>
<contextPath>/${project.name}</contextPath>
</webAppConfig>
<scanIntervalSeconds>5</scanIntervalSeconds>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<logLevel>INFO</logLevel>
<style>PRETTY</style>
<runTarget>/gwtapp.html</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<modules>
<module>${project.groupId}.gwtapp</module>
</modules>
<copyWebapp>true</copyWebapp>
</configuration>
<executions>
<execution>
<id>gwtcompile</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
</build>
This will cause the compile and gwt-compile to run., assuming you have those configured correctly.
If your config looks like this, you can just run mvn clean integration-tests and your script will:
Compile your code
gwt:compile your code
Create the war file
start jetty and deploy the war file to jetty
Start the Selenium server
try to run any tests in any subdirectory of the integration package in your test directory.

Resources