首页 文章

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

提问于
浏览
5

我有一个简单的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 回答

  • 5

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

    repositories {
        mavenCentral()
    }
    

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

相关问题