How to change sonar-maven-plugin version in Jenkins?

SonarQube: 9.6
SonarQube Scanner:
SonarQube Scanner for Jenkins: 2.14

When I build maven project, version is used for sonar-maven-plugin. I know I can specify that in the project pom.xml. But I want to see how I can set the plugin version in Jenkins. Thanks.

Welcome :slight_smile:

it is recommended to use the latest version of Sonarqube Maven plugin, at the moment it is

There are different ways to configure the plugin version in Maven, settings.xml … pom.xml … mvn cli
see SonarScanner for Maven | SonarQube Docs

but that is independent from Jenkins.


1 Like

Thanks for the reply.

Currently the version used is Where is this value set? I want to update the value in the same place. I didn’t define any sonarqube related configuration in maven pom.xml.

If you simply remove the sonar plugin from your pom.xml, and then run “mvn sonar:sonar”, you will get the latest version available without having to specify it. However, if for some reason you have a need to specify the version to use, just use something like “mvn org.sonarsource.scanner.maven:sonar-maven-plugin:”.

1 Like

Thanks. I saw that the value of injected SONAR_MAVEN_GOAL is “sonar:sonar”. I assume maven should use the latest, but actually it still uses version 3.7. Perhaps it’s maven issue. No idea.

Edit: I got 2 ways to fix my problem.

The first one is to specify the version in Jenkins explicitly.

  1. Go to “Manage Jenkins”
  2. Go to “Configure System”
  3. Under “SonarQube servers” section, press the “Advanced” button
  4. Put the version in “Version of sonar-maven-plugin”
  5. Rebuild the project. In this case, the injected SONAR_MAVEN_GOAL will become “org.sonarsource.scanner.maven:sonar-maven-plugin:<version>:sonar”

The second one is to force maven to redownload the latest plugin.

  1. Login to the jenkins server
  2. Go to “$M2_HOME/.m2/repository/org/codehaus/mojo”
  3. Rename the directory “sonar-maven-plugin” to “sonar-maven-plugin-backup”
  4. Rebuild the project. Jenkins / Maven will redownload the latest plugin. The injected SONAR_MAVEN_GOAL will still be “sonar:sonar”
  5. If everything looks good, delete the “sonar-maven-plugin-backup” directory in server.

Reference: SonarBuildWrapper class in " SonarQube Scanner for Jenkins" determines the value of SONAR_MAVEN_GOAL. (sonar-scanner-jenkins/ at 86c09f1d90eecc514dd69c00965457912362f898 · SonarSource/sonar-scanner-jenkins · GitHub)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.