2017-01-23 75 views
0

我工作的一個多個項目gradle這個項目,主要build.gradle是這樣的:的Cobertura + gradle這個 - 爲什麼我不能運行的Cobertura任務?

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這個包裝,失敗和控制檯輸出爲:

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 

這到底是怎麼回事?

回答

2

就像錯誤消息告訴您。

你已經在你的根項目宣佈net.sourceforge.cobertura:cobertura:2.0.3的依賴(因爲它沒有明確的添加,我猜的搖籃的Cobertura插件添加它含蓄,它的文檔或許應該這麼說),但你沒有定義的任何資源庫爲您的根項目。你只宣佈參加buildscript(解決搖籃插件之類的東西),並在subprojects關閉所有分項目庫。定義庫還爲根項目,或者單獨,或者通過使用allprojects關閉和您的版本應該可以正常工作,在這方面,至少。