【问题标题】:Gradle 1.9 with Jacoco plugin cannot find jacoco agent带有 Jacoco 插件的 Gradle 1.9 找不到 jacoco 代理
【发布时间】:2013-11-28 15:26:29
【问题描述】:

我有一个简单的 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 的经验很少。

谢谢!

【问题讨论】:

    标签: java gradle jacoco


    【解决方案1】:

    您没有在构建中定义存储库。对于许多人来说,这将是 Maven Central。

    repositories {
        mavenCentral()
    }
    

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

    【讨论】:

    • 愚蠢的我。我想我假设 Gradle 会有一些默认的 repo 来降低插件依赖项。谢谢你,让我又省了 N 个小时盯着这个看!你是对的,我可能会拉下那些 Jacoco 依赖项并对其进行源代码控制。我们有一个政策,无论好坏,我们对所有依赖项进行源代码控制。
    猜你喜欢
    • 1970-01-01
    • 2014-07-08
    • 2019-08-11
    • 2017-10-07
    • 2018-12-18
    • 2013-11-16
    • 2017-12-25
    • 2015-08-03
    • 2016-12-03
    相关资源
    最近更新 更多