Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 1.9 with Jacoco plugin cannot find jacoco agent

I have a simple Java project with some tests that I am building with Gradle 1.9. I am attempting to add Jacoco to the build following instructions at: http://www.gradle.org/docs/current/userguide/jacoco_plugin.html

When I run:gradle clean build jacocoTestReport I get the following build failure:

FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':test'.
    > Could not resolve all dependencies for configuration ':jacocoAgent'.
       > Could not find org.jacoco:org.jacoco.agent:0.6.2.201302030002.
         Required by:
             :Phoenix:1.0

My build.gradle file is:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'

sourceCompatibility = 1.7
version = '1.0'

test {
  // enable TestNG support (default is JUnit)
  useTestNG()

  // listen to events in the test execution lifecycle
  beforeTest { descriptor ->
     logger.lifecycle("Running test: " + descriptor)
  }

  // listen to standard out and standard error of the test JVM(s)
  onOutput { descriptor, event ->
     logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
  }
}

sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
    test {
        java {
            srcDir 'test'
        }
    }
}

jar {
    manifest {
        attributes 'Implementation-Title': 'SQLWriter', 'Implementation-Version': version
    }
}

dependencies {
    compile files('./lib/commons-codec-1.6.jar')
    runtime files('./lib/hamcrest-core-1.3.jar')
    runtime files('./lib/sqlite-jdbc-3.7.2.jar')
    compile files('./lib/testng-6.8.jar')
    runtime files('./lib/testng-6.8.jar')
}

task doc(type: Javadoc) {
  source = sourceSets.main.allJava
}

jacoco {
    toolVersion = "0.6.2.201302030002"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

Can anyone tell me what I'm missing? I suspect that the Jacoco plugin documentation may be out of date or incompatible with the latest version of Gradle, but I have very little experience with Gradle at this point.

Thanks!

like image 228
Mark Roper Avatar asked Nov 28 '13 15:11

Mark Roper


People also ask

How do I get Jacoco code coverage report gradle?

Run gradle build jacocoTestReport to generate JaCoCo code coverage report. and then just run gradle build . JaCoCo report will be generated at each build task execution. It works in similar fashion as the previous option, but generates report after every execution of test task.

Why is JaCoCo not showing coverage for some classes?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.


1 Answers

You are not defining a repository in your build. For many people that would be Maven Central.

repositories {
    mavenCentral()
}

It seems as if you want to manage your libraries yourself as you are pointing to the lib folder. I assume these libraries are checked in with your source code? If the same strategy should apply to the JaCoCo libraries then you will need to put them there and assign them to the configurations of the JaCoCo plugin.

like image 199
Benjamin Muschko Avatar answered Sep 25 '22 16:09

Benjamin Muschko