Покрытие ветки не отображается в Sonarcloud при синхронизации с основной веткой

Я пытаюсь выполнить анализ своего кода с помощью подключаемого модуля jacoco в gradle и sonarqube. Мои тесты написаны на Groovy. Я автоматизировал этот процесс с помощью конвейеров bitbucket, поэтому каждый раз, когда я фиксирую код, запускаются тесты, и в конце запускаются jacoco-анализ и sonarqube, отправляя результаты отчета в SonarCloud. Покрытие отображается (в процентах, со ссылкой на классы) и сравнивается с веткой dev (я явно указал dev как долгоживущую ветвь в SonarCloud). Также показано общее покрытие (после слияния).

Проблема в том, что когда я объединяю dev в свою ветку (что-то еще объединяется с dev, поэтому я синхронизирую), тогда покрытие ветки отображается как «-», то есть пусто. Кажется, я не могу найти проблему, вместо того, чтобы предположить, что фиксация (которая происходит от слияния dev в мою ветку) имеет 2 родителя (предыдущая фиксация и другая недолговечная ветка, которая была объединена в dev), и каким-то образом это путается. После того, как я что-то фиксирую, даже глупую строчку кода, анализ снова отображается правильно.

Я хотел бы знать, решил ли кто-нибудь эту проблему или знает, почему это происходит. Спасибо!

В build.gradle я добавил:

 plugins {
    id "org.springframework.boot" version "2.0.2.RELEASE"
    id "org.sonarqube" version "2.7.1"
    id "application"
    id "jacoco"
}

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.8.3"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("$buildDir/jacocoHtml")
    }
}

sonarqube {
   properties {
        // properties related to credentials
    }
}

и мой файл конвейеров битбакета:

image: java:8

clone:
  depth: full  # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - gradle
          - sonar
        script:
          - ./gradlew clean test
          - ./gradlew jacocoTestReport
          - ./gradlew sonarqube
        artifacts:
          - build/libs/**

pipelines:
  default:
    - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

person gfe    schedule 21.05.2019    source источник


Ответы (1)


В build.gradle достаточно указать свойства jacoco и jacocoTestReport следующим образом:

jacoco {
    toolVersion = "0.8.3"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled true
        csv.enabled false
        html.destination file("$buildDir/customJacocoReportDir/test/html")
        xml.destination file("$buildDir/customJacocoReportDir/test/jacocoTestReport.xml")
    }
}

sonarqube {
    properties {
        // define your properties
        property "sonar.jacoco.reportPath", "$buildDir/jacoco/test.exec"
        property "sonar.coverage.jacoco.xmlReportPaths", "$buildDir/customJacocoReportDir/test/jacocoTestReport.xml"
    }
}

А затем в bitbucket-pipelines.yml сделайте следующее:

image: java:8

clone:
  depth: full  # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - gradle
          - sonar
        script:
          - ./gradlew clean test
          - ./gradlew jacocoTestReport
          - ./gradlew sonarqube
        artifacts:
          - build/libs/**

pipelines:
  default:
    - step: *build-test-sonarcloud
person gfe    schedule 20.08.2019