使用Jacoco插件的Gradle 1.9找不到jacoco代理

时间:2013-11-28 15:26:30

标签: java gradle jacoco

我有一个简单的Java项目,其中包含一些使用Gradle 1.9构建的测试。我正在尝试按照以下说明将Jacoco添加到构建中:http://www.gradle.org/docs/current/userguide/jacoco_plugin.html

当我运行时:gradle clean build jacocoTestReport我遇到以下构建失败:

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

我的build.gradle文件是:

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."
}

谁能告诉我我缺少什么?我怀疑Jacoco插件文档可能已过时或与最新版本的Gradle不兼容,但此时我对Gradle的经验很少。

谢谢!

1 个答案:

答案 0 :(得分:5)

您没有在构建中定义存储库。对于许多将成为Maven Central的人来说。

repositories {
    mavenCentral()
}

当您指向lib文件夹时,似乎您想要自己管理库。我假设这些库已使用您的源代码签入?如果相同的策略应该应用于JaCoCo库,那么您需要将它们放在那里并将它们分配给JaCoCo插件的configurations