添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I applied the Jacoco plugin and tried to generate the codeCoverage report. I used jacoco ‘0.6.2.201302030002’ version and gave the required dependencies jars of jacoco.agent and jacoco.ant-0.6.2.201302030002. When execute the gradle jacocoTestReport task it gives bellow error. “taskdef A class needed by class org.jacoco.ant.ReportTask cannot be found: org/jacoco/core/analysis/ICoverageVisitor using the classloader AntClassLoader[C:\LTC_P360\LTCWsBase\lib\org.jacoco.ant-0.6.2.201302030002.jar]”. If I used jacoco-0.6.1.201212231917 version and its ant and agent, jars it is working. how to use latest version of jacoco with gradle?

This is my build script. I’m using Gradle 1.10 version.

group = ‘com.nyl.ltc’

apply plugin : ‘java’ apply plugin: ‘application’ apply plugin: ‘project-report’ apply plugin: “jacoco”

buildDir = “$projectDir/bin”

allprojects {

repositories {

flatDir { dirs “…/lib” }

flatDir { dirs “lib” }

flatDir { dirs “…/XmlTransformer/lib” }

flatDir { dirs “C:/IBM/SDP/runtimes/base_v7/feature_packs/xml/plugins” } // repository location for IBM jars

flatDir { dirs “C:/IBM/SDP/runtimes/base_v7/plugins” }

flatDir { dirs “C:/IBM/SDP/runtimes/base_v7/lib” }

flatDir { dirs “C:/IBM/SDP/runtimes/base_v7/java/jre/lib” }

flatDir { dirs “C:/IBM/SDP/runtimes/base_v7/runtimes” }

configurations { providedCompile }

sourceSets.main.compileClasspath += configurations.providedCompile sourceSets.test.compileClasspath += configurations.providedCompile sourceSets.test.runtimeClasspath += configurations.providedCompile

sourceSets {

main {

java {

srcDir “$projectDir/src”

resources {

srcDir “$projectDir/WebContent/WEB-INF/wsdl”

srcDir “$projectDir/WebContent/WEB-INF/conf”

srcDir “$projectDir/test/WEB-INF/conf”

exclude ‘_serena’

test {

java.srcDirs = ["$projectDir/test"]

resources.srcDirs = ["$projectDir/test"]

compileClasspath += configurations.testCompile

runtimeClasspath += sourceSets.test.output

clean.doLast {

mkdir("$projectDir/bin") }

compileJava.doFirst {

println ‘copying from LTCWsBase’

copy {

from “$projectDir/src/LTCWsBase”

into “$projectDir/bin/resources/main/LTCWsBase”

exclude ‘_serena’

dependencies {

providedCompile (group: ‘logback-audit’ , name: ‘audit-client’ , version: ‘0.6’) { project.ext.provided = true }

providedCompile (group: ‘logback-audit’ , name: ‘audit-common’ , version: ‘0.6’) { project.ext.provided = true }

providedCompile (group: ‘slf4j’ , name: ‘slf4j-jdk14’ , version: ‘1.7.5’)

providedCompile (group: ‘slf4j’ , name: ‘slf4j-api’ , version: ‘1.7.5’ )

providedCompile (group: ‘guava’ , name: ‘guava’, version: ‘15.0’)

providedCompile (group: ‘ibm’ , name: ‘com.ibm.xml’)

providedCompile group: ‘J2EE’, name: ‘j2ee’

providedCompile group: ‘J2EE’, name: ‘rt’

providedCompile (group:‘asia.redact.bracket.properties’ , name:‘bracket-properties’ , version: ‘1.3.4’)

providedCompile (group: ‘ibm’ , name: ‘com.ibm.ws.admin.client_7.0.0’)

compile(project(":XmlTransformer"))

providedCompile (group: ‘ch.qos.logback’, name: ‘logback-core’, version: ‘1.0.11’)

testCompile (group: ‘junit’, name:‘junit’, version:‘4.11’)

testCompile (group: ‘xmlunit’ , name: ‘xmlunit’ , version: ‘1.5’)

testCompile (group: ‘org.hamcrest’ , name: ‘hamcrest-core’, version: ‘1.3’)

testCompile (group: ‘slf4j’ , name: ‘slf4j-jdk14’ , version: ‘1.7.5’)

testCompile (group: ‘slf4j’ , name: ‘slf4j-api’ , version: ‘1.7.5’ )

testCompile (group: ‘mock’, name:‘cglib-nodep’, version:‘2.2.2’)

testCompile (group: ‘mock’, name:‘easymock’, version:‘3.1’)

testCompile (group: ‘mock’, name:‘javassist’, version:‘3.18.1-GA’)

testCompile (group: ‘mock’, name:‘objenesis’, version:‘2.1’)

testCompile (group: ‘mock’, name:‘powermock-easymock’, version:‘1.5.1-full’)

providedCompile (group: ‘org.jacoco’, name:‘org.jacoco.agent’, version:‘0.6.2.201302030002’)

providedCompile (group: ‘org.jacoco’, name:‘org.jacoco.ant’, version:‘0.6.2.201302030002’) }

test {

testClassesDir = sourceSets.test.output.classesDir

testLogging {

events ‘started’, ‘passed’

exceptionFormat = ‘full’

scanForTestClasses = false

include “**/*Test.class”

return true }

htmlDependencyReport{}

jacoco {

toolVersion = “0.6.2.201302030002”

reportsDir = file("$buildDir/JacocoCodeCoverageReportDir") }

task applicationCodeCoverageReport(type:JacocoReport){

executionData run

sourceSets sourceSets.main }

/////

tasks.withType(Compile) {

options.debug = true

options.compilerArgs = ["-g"]

} /////

Sorry for the inconvenience. Bellow scripts are relevant to the jacoco code coverage report. Thanks for your support.

apply plugin : ‘java’ apply plugin: ‘jacoco’

dependencies {

providedCompile (group: ‘org.jacoco’, name:‘org.jacoco.agent’, version:‘0.6.2.201302030002’)

providedCompile (group: ‘org.jacoco’, name:‘org.jacoco.ant’, version:‘0.6.2.201302030002’) }

jacoco {

toolVersion = “0.6.2.201302030002”

reportsDir = file("$buildDir/JacocoCodeCoverageReportDir") }

task applicationCodeCoverageReport(type:JacocoReport){

executionData run

sourceSets sourceSets.main }

Why do you declare the JaCoCo dependencies yourself, rather than leaving this to the plugin? Also, the dependencies have to go on the ‘jacocoAgent’ and ‘jacocoAnt’ configurations, respectively. Otherwise, the dependency declarations won’t be used by the JaCoCo plugin.

PS: Please use HTML code tags for all code snippets.

That’s the same error as with your declarations, which just proves that they don’t do anything. One possible cause for the error is that you don’t have the correct dependencies in your ‘flatDir’ repositories. I recommend to first try with a ‘mavenCentral()’ repository, then make sure you provide the exact same dependencies (verify by running ‘gradle dependencies’ and finding/downloading the dependencies via http://search.maven.org ) via your ‘flatDir’ repositories.

I’m seeing this same error message. In my case, I need to use a special version of Jacoco because I’m building with Java 8 byte codes, and the shipping version of Jacoco doesn’t support it yet. My build script is as such:

apply plugin: 'java'
apply plugin: 'osgi'
apply plugin: 'jacoco'
  test{
    useTestNG()
  jacoco {
    toolVersion = '0.6.4.201311160552'

This is a sub-project. The top-level project defines the repositories:

allprojects {
    repositories {
        maven {
            url 'internal-repository-url-goes-here'

The test process works fine, and I know it is instrumenting with jacoco because before I used the right libraries (https://github.com/jacoco/jacoco/issues/74). Now that I’m using the right jacoco library, it is building fine. However when it comes to generating the report, it fails because the ant task doesn’t have the right version of the jacoco core jar:

FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':Device:ApplicationFramework:jacocoTestReport'.
> taskdef A class needed by class org.jacoco.ant.ReportTask cannot be found: org/jacoco/core/analysis/ICoverageVisitor
   using the classloader AntClassLoader[/Users/rbair/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.ant/0.6.4.201311160552/215bfbeaccfcb5dcfc55523effe956ca168ebd68/org.jacoco.ant-0.6.4.201311160552.jar]
              

If you don’t take the artifacts from Maven Central, make sure that your artifacts are packaged exactly in the same way as those on Central. (Note that the jacoco-agent Jar on Central contains another Jar.) If this doesn’t help, then I suspect it’s a JaCoCo problem (e.g. jacoco-ant not yet updated for jacoco-agent).