EzDevInfo.com

jacoco

<img class="emoji" title=":microscope:" alt=":microscope:" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f52c.png" height="20" width="20" align="absmiddle"> JaCoCo Java Code Coverage Library EclEmma - JaCoCo Java Code Coverage Library

Android test code coverage with JaCoCo Gradle plugin

I'm new to Gradle and Android testing but I've already converted my Android project to build with Gradle.

Now I'm trying to perform test coverage of an Android project with Gradle's JaCoCo plugin.

I've added the following to my build.gradle file:

apply plugin: 'jacoco'

And when I run "gradle jacocoTestReport" the following error:

Task 'jacocoTestReport' not found in root project '<project name>'.

From the documentation I'm supposed to also apply plugin 'java' but it conflicts with plugin 'android'.

Is there a way around this?

Thanks in advance.


Source: (StackOverflow)

Jacoco and Unit Tests Code Coverage with android-gradle-plugin >= 1.1

I recently started integration android-gradle-plugin 1.1.0 in one of my projects. The project uses robolectric 2.4 to run unit tests.

It's a multi module project with very complex dependencies (Some modules depend on other modules). Something like that:

--> application-module (dependsOn: module1, module2, module-core)
    --> module1 (dependsOn: module-core)
    --> module2 (dependsOn: module-core)
    --> module-core (dependsOn: module3, module4)
        --> module3 (library dependencies)
        --> module4 (library dependencies)

For a more cleared picture please see jacoco-example project.

I tried to integrate JaCoCo to generate reports for the unit tests, but it seams to me that it runs only androidTests which are basically instrumentation tests.

After some google'ing I've came across a few projects on GitHub and other articles, but they mainly are focused on previous versions of the android-gradle-plugin or are using other third party plugins like android-unit-test for example here.

May be I've lost my ability to google. But can somebody point me in a direction where I can find some documentations regarding the new stuff in android gradle plugin and how to run the jacoco task only for unit tests?

UPDATE

Adopted the script from nenick's example:

apply plugin: "jacoco"

configurations {
    jacocoReport
}

task jacocoReport(dependsOn: 'testDebug') << {
    ant {
        taskdef(name:'jacocoreport',
                classname: 'org.jacoco.ant.ReportTask',
                classpath: configurations.jacocoReport.asPath)

        mkdir dir: "${buildDir}/test-coverage-report"
        mkdir dir: "${buildDir}/reports/jacoco/test/"

        jacocoreport {
            executiondata = files("${buildDir}/jacoco/testDebug.exec")

            structure(name: "${rootProject.name}") {
                classfiles {
                    fileset (dir: "${buildDir}/intermediates/classes/debug") {
                        //exclude(name: '**/*_*.class')
                        exclude(name: '**/R.class')
                        exclude(name: '**/R$*.class')
                        exclude(name: '**/BuildConfig.class')
                    }
                }

                sourcefiles {
                    fileset dir: "src/main/java"
                    fileset dir: "${buildDir}/generated/source/buildConfig/debug"
                    fileset dir: "${buildDir}/generated/source/r/debug"
                }
            }

            xml destfile: "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
            html destdir: "${buildDir}/test-coverage-report/"
        }
    }
}

dependencies {
    jacocoReport 'org.jacoco:org.jacoco.ant:0.7.2.201409121644'
}

After that the ./gradlew jacocoReport executes and generates the report, but it shows 0 (zero) test coverage, which is impossible because at least half of all classes are tested.

UPDATE_2

Tried out this example. Adding the next task to one of my gradle build files:

task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports"

    classDirectories = fileTree(
            dir: "${buildDir}/intermediates/classes/debug",
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/*$ViewInjector*.*',
                       '**/BuildConfig.*',
                       '**/Manifest*.*']
    )

    sourceDirectories = files("${buildDir.parent}/src/main/java")
    additionalSourceDirs = files([
            "${buildDir}/generated/source/buildConfig/debug",
            "${buildDir}/generated/source/r/debug"
    ])
    executionData = files("${buildDir}/jacoco/testDebug.exec")

    reports {
        xml.enabled = true
        html.enabled = true
    }
}

Same issue, the reports are generated, but the code coverage is still zero.

UPDATE_3

It seams that the task from UPDATE_2 worked but only for the module with apply plugin: 'com.android.application' (The reports a generated correctly). But for modules that are android libraries (apply plugin: 'com.android.library') the reports show zero coverage, altho the modules contain more tests then the application module.

UPDATE_4

Created a simple example project that demonstrates my issue. Currently if you run ./gradlew jacocoReport the report is generated, but no test coverage is displayed for the module projects. See this link

Short note: When the test where AndoridUnitTests (whiteout JUnit 4 and Robolectric) JaCoCo reports showed coverage for all the modules.

Any ideas?


Source: (StackOverflow)

Advertisements

Jacoco Maven Plugin - Plugin execution not covered by lifecycle configuration

I'm new to Maven and want to use the Jacoco Maven Plugin to build my projects.

I've set up an example project with TestNG the only dependency.

Here is part of the pom.xml:

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.6.2.201302030002</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

And i get this error:

Plugin execution not covered by lifecycle configuration: org.jacoco:jacoco-maven- plugin:0.6.2.201302030002:prepare-agent (execution: default, phase: initialize)

What am I doing wrong ? Cheers


Source: (StackOverflow)

Continuous integration: ensure new commits are covered with tests

I'm working on a project that has a lot of legacy code that is not covered with tests.

Is there any way that I could set up the integration server to check that all new commits have a minimum amount of tests (say, coverage is >70%)?

Essentially, I see two options:

  1. Somehow set up the CI server to fail the build when the committed changes are not covered with unit tests. This will ensure that every piece of new code will have tests and that tests for the legacy code will increase with each change.
  2. Set a coverage threshold for the whole project and fail the build if the coverage percentage decreases after a commit. The problem with this is that if I delete a class containing 100 instructions and add a new class with 50 instructions the coverage percentage will go up without me writing any tests.

I like option 1 more because it forces changes in legacy code to be unit tested. This should increase the overall test coverage.

Right now we're using Jenkins as our CI server and JaCoCo for test coverage. Maven is used for building the project and SVN is our main source control.


Source: (StackOverflow)

JaCoCo - exclude JSP from report

In the Maven site reports generated by JaCoCo, I get quite bad coverage because all of my compiled JSPs are included (and they are long). I tried the following in reporting:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <exclude>target/classes/jsp/**/*.class</exclude>
    </configuration>
</plugin>

Another similar-looking configuration is in the build section of the POM for the prepare-package phase. That doesn’t stop the JSP classes from being included in the report. How to avoid that?


Source: (StackOverflow)

Missing branches when using assertTrue instead of assertNull

In Java/Junit, I need to test for null with some object. There are a variety of ways I can test a condition but I have been using assertTrue for most of my tests. When I check for nulls in an assertTrue, EclEmma states that it is only testing one branch.

When I resolve the statement into a variable manually (like setting the result to a boolean and passing it into assertTrue) the code coverage is deemed complete on the assert but not on the variable initializing line.

Why is this happening? Is this related to the extra byte code that Java apparently adds as mentioned on http://sourceforge.net/apps/trac/eclemma/wiki/FilteringOptions? Any solutions (besides using other assert statements).

assertTrue:

assertTrue( myObject == null ); //1 of 2 branches

assertTrue:

boolean test = (myObject == null); //1 of 2 branches missing
assertTrue(test); // complete

assertNull:

assertNull( myObject ) //complete;

Source: (StackOverflow)

SonarQube on Java8-project gives jacoco-Exception

I just downloaded the latest version, SonarQube 4.3, then try build a java-8 project with:

  mvn clean install
  mvn sonar:sonar

That gives me the Exception below.

Googling, I got the impression this is an earlier issue that should have been fixed... ?

http://sonarqube.15.x6.nabble.com/Sonar-analyze-Java-1-8-project-Failure-td5023663.html

http://jira.codehaus.org/browse/SONARJAVA-482

Does SonarQube 4.3 support java-8?

Or any clue, what is the problem?

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
        at org.jacoco.agent.rt.internal_6effb9e.PreMain.createRuntime(PreMain.java:55)
        at org.jacoco.agent.rt.internal_6effb9e.PreMain.premain(PreMain.java:47)
        ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
        at java.lang.Class.getField(Class.java:1690)
        at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
        ... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"

Source: (StackOverflow)

Jacoco code coverage in Android Studio with flavors

I've been trying to run Jacoco test coverage for quiet some time now. I've tried several possible solutions reported in these topics:

Android test code coverage with JaCoCo Gradle plugin

How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

Im running the tests in a emulatated device using genymotion. Here is what i added to build.gradle:

apply plugin: 'jacoco'

android{       
    jacoco {
        version "0.7.1.201405082137"
    }        
    buildTypes{
        debug{
                    testCoverageEnabled = true
        }
    }
}

jacoco {
    toolVersion "0.7.1.201405082137"
}

To run it i use something like

./gradlew clean
./gradlew createFLAVOR_NAMEDebugCoverageReport

The relevant generated files/folder are:

/build/intermediates/coverage-instrumented-classes
/build/intermediates/jacoco
/build/outputs/code-coverage/connected/flavors/MyFlavor/coverage.ec

However, there is nothing @ build/reports/jacoco/test/html/index.html or any html page/code coverage report @ /build/outputs.

I've also tried to create a dedicated task to build a coverage report:

def coverageSourceDirs = [
    'src/main/java',
]

task jacocoTestReport(type: JacocoReport, dependsOn: "connectedAndroidTestFLAVOR_NAMEDebug") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
        dir: './build/intermediates/classes/debug',
        excludes: ['**/R*.class',
                   '**/*$InjectAdapter.class',
                   '**/*$ModuleAdapter.class',
                   '**/*$ViewInjector*.class'
        ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/connectedAndroidTestMyFlavorDebug.exec")
    // Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
    // We iterate through the compiled .class tree and rename $$ to $.
    doFirst {
       new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

Then ./gradlew clean and ./gradlew jacocoTestReport. The output is the same as above, so, no html page with coverage report or any other coverage file.

I'm currently using Android Studio v1.0.2 with the latest gradle version. Im fairly new to gradle, so it is possible im missing something basic here.

Thanks


Source: (StackOverflow)

Jacoco Code Coverage in android studio

I am trying to generate Jacoco code coverage report. I have used AndroidTestCase for my test classes.

I have found using testCoverageEnabled true and using default android -studio default jacoco, ./gradlew connectedCheck or createDebugCoverageReport create the percentage of successfull/fail test cases, but no coverage report.

Then I have tried jacoco {toolVersion "0.7.1.201405082137"}, and task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug"). I have tried to change the dependsOn value with various task. The report shows 0 (zero) test coverage, which is impossible because at least half of all classes are tested.

I have followed various accepted answer of stack overflow in last couple of days. The result is negative.

My gradle file:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'        
    }
}

apply plugin: 'com.android.application'
apply plugin: 'jacoco'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "test.gradle.com.myapplicationtestgradle"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false            
            proguardFiles getDefaultProguardFile(
            'proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }

    jacoco {
        version "0.7.1.201405082137"
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }
}


jacoco {
    toolVersion "0.7.1.201405082137"
}

task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"

    description = "Generate Jacoco coverage reports"

   // exclude auto-generated classes and tests
    def fileFilter = ['**/R.class', '**/R$*.class', 
    '**/BuildConfig.*', '**/Manifest*.*',           
     'android/**/*.*']
    def debugTree = fileTree(dir:   
    "${project.buildDir}/intermediates/classes/debug", 
    excludes: fileFilter)
    def mainSrc = "${project.projectDir}/src/main/java"

    sourceDirectories = files([mainSrc])
    classDirectories = files([debugTree])
    additionalSourceDirs = files([
            "${buildDir}/generated/source/buildConfig/debug",
            "${buildDir}/generated/source/r/debug"
    ])
    executionData = fileTree(dir: project.projectDir, includes: 
                    ['**/*.exec', '**/*.ec'])

    reports {
        xml.enabled = true
        xml.destination = "${buildDir}/jacocoTestReport.xml"
        csv.enabled = false
        html.enabled = true
        html.destination = "${buildDir}/reports/jacoco"
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }
}

Source: (StackOverflow)

Running jacocoReport

I'm using gradle 1.7 and jacoco plugin. My project uses java and scala plugins

When I run gradlew -i clean jacocoTestReport

Report is not created and I see in the log

:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main] - start
:bl:jacocoTestReport
Skipping task ':bl:jacocoTestReport' as task onlyIf is false.
:bl:jacocoTestReport SKIPPED
:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main]) - complete

What does it mean? Why report is not created?


Source: (StackOverflow)

jacoco's prepare-agent not generating jacoco.exec file

I am running Jacoco's Maven plugin. The prepare-agent goal runs fine, but does not generate jacoco.exec file for some reason. Subsequently the report goal complains Skipping JaCoCo execution due to missing execution data file.

Any ideas?


Source: (StackOverflow)

How to calculate code coverage of selenium tests with respect to web application code

I do have an requirement to capture the code coverage of my selenium tests to the amount of source code in the server code (web application source code) covered .

For example the tests for login functionality should capture the amount of code covered in web application for the login function.

Else need to know which package or class it has touched in web application code for a scenario done . Eg a login

I couldn't find a suitable solution , although i came to know about Jacoco code coverage tool and tried some samples with the use of Jacoco Jenkins plugin , but there is no success .

I am not aware of the possiblity. Please provide me a suggestion on how to achieve this , Thanks in advance


Source: (StackOverflow)

Tomcat7 Maven Plugin and JaCoCo

Is there any way to get code coverage using JaCoCo with the tomcat7-maven-plugin embedded instance?

The jacoco-maven-plugin is configured in my WAR's POM to instrument my unit tests, but I'm not sure how to attach the jacoco agent to the embedded Tomcat instance to instrument my integration tests that run against Tomcat. Given that the Tomcat instance is embedded, I'm not sure if this approach is possible. Is there any other way to accomplish this? I can probably switch from using the Tomcat Maven Plugin to using Cargo to get coverage, but I'd prefer to stick with the Tomcat plugin if possible.

Here are a few relevant snippets from my POM:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.6.2.201302030002</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.14</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <systemProperties>
            <!-- as expected, this system property doesn't work since Tomcat is embedded, but this is the type of config I'm looking for -->
            <JAVA_OPTS>-javaagent:${project.build.directory}/${jacoco.jar}=destfile=${project.build.directory}/jacoco.exec,append=true</JAVA_OPTS>
        </systemProperties>
    </configuration>
    <executions>
        <execution>
            <id>tomcat-startup</id>
            <goals>
                <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <fork>true</fork>
            </configuration>
        </execution>
        <execution>
            <id>tomcat-shutdown</id>
            <goals>
                <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>

Versions: Maven 3.0.4, Tomcat Maven Plugin 2.1, Jacoco 0.6.2.201302030002, Java 7


Source: (StackOverflow)

Unable to get Jacoco to work with Powermockito using offline instrumentation

Given that Jacoco doesn't play nicely with PowerMockito when instrumenting "on the fly", I've been trying to configure offline instrumentation in the hope this will give me proper unit test coverage for classes that use PowerMockito.

I've setup my pom as below but I still get zero % coverage on my test class. Any help much appreciated as it's driving me slowly bonkers!

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mandy</groupId>
    <artifactId>jacoco-test</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jacoco-test Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <powermock.version>1.5.4</powermock.version>
        <jacoco.version>0.7.1.201405082137</jacoco.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <classifier>runtime</classifier>
            <version>${jacoco.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restore-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <!--<argLine>${argLine}</argLine>-->
                    <systemPropertyVariables>
                        <!-- JaCoCo runtime must know where to dump coverage: -->
                        <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
        <finalName>jacoco-test</finalName>
    </build>
</project>

here is my class under test:

public class Utils {

    private Utils() {

    }

    public static String say(String s) {
        return "hello:"+s;
    }
}

here is my test:

@RunWith(PowerMockRunner.class)

@PrepareOnlyThisForTest(Utils.class)
@PowerMockIgnore("org.jacoco.agent.rt.*")
public class UtilsTest {

    @Test
    public void testSay() throws Exception {
        PowerMockito.mockStatic(Utils.class);
        Mockito.when(Utils.say(Mockito.anyString())).thenReturn("hello:mandy");
        assertEquals("hello:mandy", Utils.say("sid"));
    }

}

I run mvn clean install which generates the jacoco.exe

Coverage report (generated from jacoco.exec using an ant script ):-

Coverage report


Source: (StackOverflow)

Maven JaCoCo plugin error

I have configured the Maven JaCoCo plugin as follows in my pom.xml file:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jacoco.version>0.5.9.201207300726</jacoco.version>
</properties>

<profiles>
    <profile>
        <id>jacoco4</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration
                            <destfile>${project.build.directory}/target/jacoco.exec</destfile>
                            <datafile>${project.build.directory}/target/jacoco.exec</datafile>
                                <output>file</output>
                                <append>true</append>
                            </configuration>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

I'm using Windows 7 and the apache-maven-3.0.4 plugin. When I type mvn -P jacoco4 install, either from a cygwin terminal or from a command prompt terminal, Maven downloads and runs the JaCoCo plugin, but then the jacoco.exec file doesn't appear to have been created. Below is the error message:

[ERROR] Unable to read execution data file C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec: C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec (The system cannot find the file specified)
java.io.FileNotFoundException: C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec (The system cannot find the file specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:120)
        at org.jacoco.maven.ReportMojo.loadExecutionData(ReportMojo.java:251)
        at org.jacoco.maven.ReportMojo.executeReport(ReportMojo.java:228)
        at org.jacoco.maven.ReportMojo.execute(ReportMojo.java:217)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

This error message appears whether or not I include the destfile and datafile specifiers in the configuration of the plugin:

<destfile>${project.build.directory}/target/jacoco.exec</destfile>
<datafile>${project.build.directory}/target/jacoco.exec</datafile>

Can someone please tell me what I'm doing wrong?


Source: (StackOverflow)