Sonarqube is not showing code coverage after running

前端 未结 3 1596
梦如初夏
梦如初夏 2021-02-19 02:29

I\'m running sonarqube with maven.

I have installed it using following way. Using brew, I installed mysql and sonar.

When

相关标签:
3条回答
  • 2021-02-19 03:15

    I had same problem, I will help you to resolve that. Here 1st thing is to walk through your pom file.

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <jacoco.version>0.8.5</jacoco.version>
        <sonar.jacoco.reportPath>target/jacoco-ut.exec</sonar.jacoco.reportPath>
        <sonar.jacoco.itReportPaths>target/jacoco-it.exec</sonar.jacoco.itReportPaths>
    </properties>
    

    In pom file, you used jacoco-ut.exec you have to use below properties on your execute SonarQube Scanner in Jenkins

    sonar.java.binaries=target/classes
    sonar.junit.reportsPath=target/surefire-reports
    sonar.surefire.reportsPath=target/surefire-reports
    sonar.jacoco.reportPath=target/jacoco-ut.exec
    

    Keep in your mind about jacoco.exec in pom and property name of executing SonarQube Scanner in Jenkins

    0 讨论(0)
  • 2021-02-19 03:17

    I've resolved this by using the following steps:

    1.To begin, I've add configuration in our pom.xml.

    <properties>
      <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
      <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
      <sonar.language>java</sonar.language>
    </properties>
    

    2.In sonarqube properties file added the below part.

    sonar.projectName=${JOB_NAME}
    sonar.projectVersion=1.0.0
    sonar.sources=src/main
    sonar.sourceEncoding=UTF-8
    sonar.language=java
    sonar.tests=src/test
    sonar.junit.reportsPath=target/surefire-reports
    sonar.surefire.reportsPath=target/surefire-reports
    sonar.jacoco.reportPath=target/jacoco.exec
    sonar.binaries=target/classes
    sonar.java.coveragePlugin=jacoco
    sonar.verbose=true
    

    0 讨论(0)
  • 2021-02-19 03:25

    I found the solution -

    The maven plugin I have included has configuration of Jacoco's destfile and datafile as ${basedir}/target/coverage-reports/jacoco-unit.exec

    but by default sonar reads at ${basedir}/target/jacoco.exec. I changed the default at http://localhost:9000/settings?category=java


    Ref: Sonar Code Coverage

    0 讨论(0)
提交回复
热议问题