首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cobertura + gradle -为什么我不能执行cobertura任务?

cobertura + gradle -为什么我不能执行cobertura任务?
EN

Stack Overflow用户
提问于 2017-01-23 11:53:56
回答 1查看 2.6K关注 0票数 0

我正在从事一个多项目的分级项目,主要的build.gradle如下所示:

代码语言:javascript
复制
buildscript {
repositories {
    mavenLocal()
    mavenCentral()
}
    dependencies {
        classpath 'net.saliman:gradle-cobertura-plugin:2.2.4'
    }
}

plugins {
    id "org.sonarqube" version "2.2.1"
}

apply plugin: 'groovy'
apply plugin: 'cobertura'

def getVersionName = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'describe', '--tags', '--always'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

ext {
    springFrameworkVersion = '4.3.4.RELEASE'
}

subprojects {
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'java'
    apply from: "${parent.projectDir.canonicalPath}/cobertura.gradle"

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenCentral()
    }

    dependencies {
        compile("org.springframework:spring-context:${springFrameworkVersion}")

        testCompile("junit:junit:4.+")
        testCompile("org.springframework:spring-test:${springFrameworkVersion}")
    }
    jar {
        version = getVersionName()
    }
}

project(':projectA') {

}

project(':projectB') {
   dependencies {
            compile project(':projectA')
        }
    }

project(':projectC') {
    dependencies {
        compile project(':projectB')
    }
}

cobertura {
    coverageFormats = ['html', 'xml']
    coverageIgnoreTrivial = true
    coverageIgnores = ['org.slf4j.Logger.*']
    coverageReportDir = new File("$buildDir/reports/cobertura")
}

但是,当我尝试使用cobertura任务运行gradle包装器时,它会失败,控制台输出是:

代码语言:javascript
复制
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':instrument'.
> Could not resolve all dependencies for configuration ':cobertura'.
   > Cannot resolve external dependency net.sourceforge.cobertura:cobertura:2.0.3 because no repositories are defined.
     Required by:
         :main-project:unspecified

这里发生什么事情?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-23 12:29:25

就像错误信息告诉你的那样。

您已经在您的根项目中声明了对net.sourceforge.cobertura:cobertura:2.0.3的依赖(因为它没有显式添加,我猜Gradle cobertura插件隐式地添加了它,它的文档可能说明了这一点),但是您没有为您的根项目定义任何存储库。您只声明了构建脚本(用于解析Gradle插件等)和subprojects闭包中的所有子项目的存储库。还可以单独定义根项目的存储库,或者使用allprojects闭包来定义存储库,至少在这方面,您的构建应该工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41805782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档