如何让sonarqube依赖jacocoTestReport?

时间:2016-04-29 18:55:13

标签: gradle sonarqube jacoco

为什么这不起作用,我怎样才能得到我想要的结果?具体来说,我希望jacoco在sonarqube之前运行。

subprojects {
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'eclipse'
    apply plugin: 'jacoco'

    test {
        jacoco {
            excludes = [...,
                         "javolution.*"]
        }
    }

    jacocoTestReport {
        dependsOn tasks.withType(Test)//This makes integrationTests go. 
    }

//This is the part that I can't get to work:
project.tasks["sonarqube"].dependsOn jacocoTestReport
}

错误是:

* Where:
Build file '/dev/abc/build.gradle' line: 92

* What went wrong:
A problem occurred evaluating root project 'abc'.
> Task with name 'sonarqube' not found in project ':thingamajig'.

当然thingamajig是一个空的父目录。没有build.gradle但是它有许多子目录都有build.gradle。我已经尝试了很多事情,例如检查任务图并在调用project.tasks.getByName()时间时吞下Exception,我猜。

1 个答案:

答案 0 :(得分:1)

子项目没有自己的声纳跑步者任务。使根项目声纳转轮任务取决于子项目jacocoTestReport任务。

在我的build.gradle中,这看起来像

if (hasProperty('sonarAnalyseOnly') && sonarAnalyseOnly.toBoolean()) {
   tasks.sonarRunner.dependsOn = []
} else {
   tasks.sonarRunner.dependsOn {
      project.subprojects.findAll { !it.sonarRunner.skipProject }.collect {
         [
               it.tasks.compileSharedJava,
               it.tasks.compileServerJava,
               it.tasks.compileGuiJava,
               it.tasks.integTest,
               it.tasks.jacocoMerge
         ]
      }.flatten()
   }
}