Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar error

sonarqube

(Surender) #1

Hi Team,

I am using sonar maven plugin with the jenkins job. sonar qube 7.1, sonar maven plugin 3.5.0.1254. I have configured my jenkins goal as sonar:sonar. Could you please let me know what could be the issue here ?

When i ran the build i can see below error. I have tried to exclude that file from in the sonar.exclusions property but it’s again showing some other file to exclude and repetitively. Can you please let me know if i have to make any changes here ?

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project : File can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]

    <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <sonar.host.url>localhost:4950</sonar.host.url>
            <sonar.projectName>Sonar Rules Test</sonar.projectName>
            <sonar.log.level>DEBUG</sonar.log.level>
            <sonar.verbose>true</sonar.verbose>
            <sonar.sources>.</sonar.sources>
            <sonar.java.binaries>${basedir}\\target\\classes</sonar.java.binaries>
            <sonar.jacoco.reportPath>${basedir}\\target\\jacoco.exec</sonar.jacoco.reportPath>
            <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
            <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
            <sonar.exclusions>.project,.classpath,**/test/**/*,**/target/**/*</sonar.exclusions>
            <sonar.coverage.exclusions>**/*.js</sonar.coverage.exclusions>
            <sonar.java.source>1.8</sonar.java.source>
        </properties>
    </profile>

I can see below warnings during the analysis, is there any alternative for sonar.jacoco.reportPath ? also how can we resolve WriteListener warning here ?

[WARNING] Property ‘sonar.jacoco.reportPath’ is deprecated. Please use ‘sonar.jacoco.reportPaths’ instead.

[WARNING] Classes not found during the analysis : [javax.servlet.WriteListener]

Thanks,
Surender


(Adam Gabryś) #2

Hello,
Sonar Scanner for Maven is responsible for generating many of parameters which you have specified. First declare only these:

<properties>
    <sonar.host.url>localhost:4950</sonar.host.url>
    <sonar.log.level>DEBUG</sonar.log.level>
    <sonar.verbose>true</sonar.verbose>
    <sonar.coverage.exclusions>**/*.js</sonar.coverage.exclusions>
</properties>

Next execute analysis mvn package sonar:sonar and verify if all important files are scanned. If no, then list here what is missing and I will help you to overwrite the defaults.

Cheers
Adam Gabryś


(Surender) #3

Thank you Adam. Build is successful after removing above properties but test case coverage was not reported. it’s showing as 0 percentage only but if i use below props i can see coverage is reported.

            <sonar.jacoco.reportPaths>${basedir}\\target\\jacoco.exec</sonar.jacoco.reportPaths>
            <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>

Also i have pushed my code to our development sonar server where i am getting below mentioned error and build got failed in dev sonar server. Can you please let me know below error significance. I have tried to add sonar.login authentication token but no luck. Is there any extra property i should in the properties section ?

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project : Protocol message end-group tag did not match expected tag. -> [Help 1]


(Adam Gabryś) #4

Did you add jacoco-maven-plugin to pom.xml? If yes, how looks its configuration?


(Surender) #5

Yeah i have added below plugin and dependency.

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.2</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
org.jacoco jacoco-maven-plugin 0.8.2 test

Build was successful and i can see coverage also after adding sonar.jacoco.reportPaths and sonar.java.coveragePlugin properties.

I have pushed the code to Jenkins but there i can see build is failing because of below error. Can you please let me know the root cause for the error.

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project : Protocol message end-group tag did not match expected tag. -> [Help 1]


(Adam Gabryś) #6

I don’t know the cause. I have a feeling the you have a problem with a proxy.


(Surender) #7

I have debugged further into this issue and looks like issue is with the quality gate. With the same quality gate build is successful in my local but it’s failed in dev sonar server. if i add <sonar.buildbreaker.skip>true</sonar.buildbreaker.skip> property to my sonar maven plugin pom.xml properties then build is successful in dev env also.

What is the signficance of breaker plugin during the maven sonar analysis ? shouldn’t the build work same in local and dev server with maven sonar plugin.

[DEBUG] 14:58:23.774 Post-jobs : org.sonar.plugins.buildbreaker.ForbiddenConfigurationBreaker@1f886b7 -> org.sonar.plugins.buildbreaker.QualityGateBreaker@bc8692

[INFO] 14:58:23.775 Executing post-job org.sonar.plugins.buildbreaker.ForbiddenConfigurationBreaker

[INFO] 14:58:23.779 Executing post-job org.sonar.plugins.buildbreaker.QualityGateBreaker


(Adam Gabryś) #8

You wrote you use SonarQube 7.1

SonarQube Build Breaker Plugin is deprecated and should not be used on SonarQube 6.4+:

SonarQube Version Plugin Version(s)
1.12 - 2.14 1.0
3.0 - 5.1 1.0, 1.1
5.2 Not compatible due to limitations with SonarQube platform
5.3 - 5.4 2.0, 2.1, 2.2
5.5 - 6.3 2.1, 2.2

The only solution is “uninstall the plugin”.

Read Why You Shouldn’t Use Build Breaker.


(Surender) #9

Thank you Adam. I will check with my build team about this plugin.

If we don’t use this plugin how build will fail if quality gate is not met by our project using sonar maven plugin. As of now we are using sonar scanner where build is failing without quality gate and we are planning to migrate all the properties to the sonar maven plugin and expecting the same behavior. Is there any other plugin are you recommending here ?


(Adam Gabryś) #10

I don’t know any plugin. You can call SonarQube Web API and check the status of the quality gate.

GET api/qualitygates/project_status since 5.3

Get the quality gate status of a project or a Compute Engine task.
Either ‘analysisId’, ‘projectId’ or ‘projectKey’ must be provided
The different statuses returned are: OK, WARN, ERROR, NONE. The NONE status is returned when there is no quality gate associated with the analysis.
Returns an HTTP code 404 if the analysis associated with the task is not found or does not exist.
Requires one of the following permissions:

  • ‘Administer System’
  • ‘Administer’ rights on the specified project
  • ‘Browse’ on the specified project

Parameters:

  • analysisId (optional) - Analysis id, example: AU-TpxcA-iU5OvuD2FL1
  • projectId (optional) since 5.4 - Project id, example: AU-Tpxb--iU5OvuD2FLy
  • projectKey (optional) since 5.4 - Project key, example: my_project

Response example:

{
  "projectStatus": {
    "status": "ERROR",
    "ignoredConditions": false,
    "conditions": [
      {
        "status": "ERROR",
        "metricKey": "new_coverage",
        "comparator": "LT",
        "periodIndex": 1,
        "errorThreshold": "85",
        "actualValue": "82.50562381034781"
      },
      {
        "status": "ERROR",
        "metricKey": "new_blocker_violations",
        "comparator": "GT",
        "periodIndex": 1,
        "errorThreshold": "0",
        "actualValue": "14"
      },
      {
        "status": "ERROR",
        "metricKey": "new_critical_violations",
        "comparator": "GT",
        "periodIndex": 1,
        "errorThreshold": "0",
        "actualValue": "1"
      },
      {
        "status": "OK",
        "metricKey": "new_sqale_debt_ratio",
        "comparator": "GT",
        "periodIndex": 1,
        "errorThreshold": "5",
        "actualValue": "0.6562109862671661"
      },
      {
        "status": "OK",
        "metricKey": "reopened_issues",
        "comparator": "GT",
        "periodIndex": 1,
        "warningThreshold": "0",
        "actualValue": "0"
      },
      {
        "status": "WARN",
        "metricKey": "open_issues",
        "comparator": "GT",
        "periodIndex": 1,
        "warningThreshold": "0",
        "actualValue": "17"
      },
      {
        "status": "OK",
        "metricKey": "skipped_tests",
        "comparator": "GT",
        "periodIndex": 1,
        "warningThreshold": "0",
        "actualValue": "0"
      }
    ],
    "periods": [
      {
        "index": 1,
        "mode": "last_version",
        "date": "2000-04-27T00:45:23+0200",
        "parameter": "2015-12-07"
      }
    ]
  }
}