I 'm using maven-sure fire plugin to execute tests and Jacoco plugin to generate the coverage reports. Jacoco does't provide coverage reports and instead fails with the debug log as shown here under.
[INFO] --- jacoco-maven-plugin:0.8.0:report (jacoco-site) # util ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Here is how the maven sure-fire plugin looks.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<parallel>classes</parallel>
<threadCount>8</threadCount>
<forkCount>4</forkCount>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
Here is how the Jacoco plugin looks like.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</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>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Quoting http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :
If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.
One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>#{argLine} -your -extra -arguments</argLine>
</configuration>
</plugin>
Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:
<properties>
<argLine>-your -extra -arguments</argLine>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- no argLine here -->
</configuration>
</plugin>
so either define
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
as property:
<build>
<properties>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- no argLine here -->
or add #{argLine} to it:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<argLine>#{argLine} -Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
Related
We are using launch4j-maven-plugin to generate an exe, used is Java 1.8.
The jar is generated with onejar because it contains jars as dependencies.
However the jar is starting immediately, only the exe needs 30s - 1m to start at first.
If I close the application after loaded completely and restart, then the application starts immediately. Maybe, because the dependencies of the jar are already loaded?!
I tried to generate with the maven-shade-plugin (only to check) and the same problem with the start occurs. Moreover I tried to start the application in a debugger and it also starts immediately. Starting the exe with --l4j-debug-all doesn't show anything.
Is there a possibility to speed-up?
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>${mainclass}</mainClass>
<attachToBuild>true</attachToBuild>
<filename>${project.artifactId}-${project.version}-jar-with-dependencies.${project.packaging}</filename>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.25</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>console</headerType>
<jar>${project.build.directory}/${project.artifactId}-${project.version}-jar-with-dependencies.${project.packaging}</jar>
<outfile>${project.build.directory}/App-${project.version}.exe</outfile>
<classPath>
<mainClass>com.simontuffs.onejar.Boot</mainClass>
<preCp>anything</preCp>
</classPath>
<jre>
<minVersion>1.8.0</minVersion>
<initialHeapSize>1024</initialHeapSize>
<maxHeapSize>1024</maxHeapSize>
</jre>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
In my case, a simple reason: the Live-Antivirus-Scan in the background slowed it down.
Why the last plugin which is to generate report for my cucumber Test Scenario run is working
Compile - Surefire SkipTest - Mvn-exec-Plgun with java- failsafe-verify
while running it from Maven
<!-- ####### maven-compiler-plugin ######### -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<!--fork>true</fork-->
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- ####### maven-surefire-plugin ######### -->
<plugin>
executions>
</plugin>
<!-- ####### maven-cucumber-reporting ######### -->
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>AutoRunner_Cucumber</projectName>
<outputDirectory>${project.build.directory}/cucumber-reports</outputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>${project.build.directory}/target/cucumber.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I've been working in Java Eclipse with a Maven project for school. I've been using Eclemma for code coverage data, but my professor wants to run my code from the command line and get a code coverage report from there. I've been trying to get Jacoco to work, but I really have never worked with Maven or Pom.xmls before and am pretty lost. Thise is what mine looks like at the moment
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId> yada yada yada </groupId>
<artifactId> yada yada yada </artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass> yada yada yada </mainClass>
</configuration>
<executions>
<execution>
<id>run-selenium</id>
<phase>integration-test</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<!-- nothing -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I execute
$> mvn clean test jacoco:report
or just jacoco:report, I get
[INFO] --- jacoco-maven-plugin:0.8.1:report (default-cli) # MyFileLocation ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Not sure what to do at this point...
Check plugins
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</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>
Add only This plugins
<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>
To record coverage using JaCoCo you need to execute tests with JaCoCo Java agent.
According to https://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :
Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test.
By default it sets property argLine which is picked by maven-surefire-plugin, however seems that you are not actually using maven-surefire-plugin and instead using java goal of exec-maven-plugin, which
first of all doesn't start new JVM - see https://www.mojohaus.org/exec-maven-plugin/java-mojo.html :
Executes the supplied java class in the current VM
second - doesn't use argLine
So make sure that JaCoCo agent is used during your tests, e.g. use exec goal of exec-maven-plugin and pass argLine to it - see https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html#arguments
Gooday,
I’m trying to get my IT in to the test coverage in sonar. I have a multi module project and I want this to work for all the modules. So as far as I got it through the documentation I found:
https://docs.sonarqube.org/display/PLUG/Usage+of+JaCoCo+with+Java+Plugin
https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven (witch are outdated btw)
http://www.eclemma.org/jacoco/trunk/doc/maven.html
Integrating JaCoCo with SONAR for unit and integration test coverage (autdated its prity based on old maven and sonar stuff and our sonar is a bit newer (6.3.1)).
But when I run it the test seems to have 0% so obviously I’m doing something wrong. Some in put on where I did go wrong would be nice.
My main Pom:
<properties>
<maven-failsafe-plugin.version>2.20.1</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.basedir}/../target/</sonar.jacoco.reportPaths>
<argLine>-Xmx256m -XX:MaxPermSize=200m</argLine>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.basedir}/../target/jacoco-ut.exec</destFile>
</configuration>
</execution>
<execution>
<id>agent-for-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
</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-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
Ive been messing with for my feeling a whole day and have not found a clear cut answer what I am doing wrong. So some input would be very helpful
well the coverage for both unit and integration tests is a bit fragile...
The configuration you have looks ok. I think what may happens is that the "argLine" property is replaced or not correctly set for the surefire or failsafe plugin. If you run the mvn goals with -X have a close look what happens when failsafe starts what its value is. The argLine should contain the jacoco agent to collect the coverage information.
Another thing: failsafe might write the coverage results into the same jacoco.exec file as surefire.
What I've done (not sure if it's the smartest of all ways): put all things in a profile and use custom properties for the jacoco-plugin and seperate files for the coverage so the sonar report can pick them up:
The sonar-jacoco-listeners is only required if you want to know what test covers which production code. In sonar this is then shown in the green bar what tests called the code.
Other than that:
The pom has some properties:
<surefire.jvm.args></surefire.jvm.args>
<failsafe.jvm.args></failsafe.jvm.args>
<jacoco.append>true</jacoco.append>
</properties>
These can be set if needed and the config uses its own properties to not conflict with the argLine (which is the default for both surefire and failsafe)
The sonar.jacoco.reportPath can be used to write one file for all maven modules, in case some integration tests are in a different module and you want to measure the coverage as well (not too nice code-wise, but well... reality and stuff):
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
Here my coverage profile: (adopt the includes: my/packages/* pattern below!)
<profile>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- prepare configuration for surefire tests -->
<execution>
<id>prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<propertyName>jacoco.agent.argLine</propertyName>
<append>true</append>
</configuration>
</execution>
<!-- prepare configuration for failsafe integration tests -->
<execution>
<id>prepare-agent-integration</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>jacoco.agent.it.argLine</propertyName>
<append>true</append>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>my/packages/*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
<argLine>${jacoco.agent.argLine} ${surefire.jvm.args}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${jacoco.agent.it.argLine} ${failsafe.jvm.args}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
So the principle is the same, setup the jacoco agent in the correct phase and run the tests. I assume the jacoco agent is not properly setup or your argLine conflicts with something happening during your build.
Is it possible to pass optional parameter testIncludes or testExcludes to maven compile plugin through the command line?
I need to pass some .java as optional parameters.
Something like
mvn clean verify test-compile -DtestIncludes=**/course/MyTest.java,**/course/CompileMeWithMyTest.java,etc
On the page http://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html testIncludes and testExcludes don't have mentioned User Property
testIncludes:
A list of inclusion filters for the compiler.
Type: java.util.Set
Since: 2.0
Required: No
testExcludes:
A list of exlusion filters for the compiler.
Type: java.util.Set
Since: 2.0
Required: No
If there is no any possible variants for the question 1.
Is it possible somehow to set include/exclude java classes/folders in the next profile using command line.
<profile>
<id>only-necessary-classes</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testIncludes>
<include>**/tests/projectname/course/CheckQuizWithNewAccount.java</include>
<include>**/tests/projectname/course/V8GenericTests.java</include>
</testIncludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Create you own property and use it in testIncludes\testExcludes blocks.
mvn clean verify -Dinclude=**/course/MyTest.java
<properties>
<include>some test</include>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testIncludes>
<include>${include}</include>
</testIncludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>