Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not execute SonarQube analysis from Jenkins

I am trying to configure Sonarqube analysis from Jenkins (using Maven). I have Sonarqube 3.7 installed. I configured the sonar jenkins plugin and it works well. I have Maven 3.0.3 and am using sonar maven plugin 2.1.

The problem is - it tries to execute the goal but asks for org.codehaus.sonar:sonar-maven3-plugin:jar:3.7. I cannot find this jar anywhere. In the repositories also, I can just see the pom for this and not the jar

Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project twister: Can not execute SonarQube analysis
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute SonarQube analysis
at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:109)
at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:67)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:109)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: org.apache.maven.plugin.PluginResolutionException: Plugin org.codehaus.sonar:sonar-maven3-plugin:3.7 or one of its dependencies could not be resolved: Failure to find org.codehaus.sonar:sonar-maven3-plugin:jar:3.7 in the local repository
like image 962
Abby Avatar asked Sep 10 '13 09:09

Abby


1 Answers

Don't be confused. There are 2 different plugins involved.

The first one is what we name "the Codehaus Sonar Mojo". This is the one you call when you do mvn sonar:sonar. The GAV of this plugin is: org.codehaus.mojo:sonar-maven-plugin We have recently released version 2.1 to support Maven 3.1. There are no frequent release of this plugin because we try to avoid any coupling with SonarQube version. When you call this plugin, it will simply do some basic checks, ask the SonarQube server for its version, then bootstrap the "SonarQube Maven plugin".

The "SonarQube Maven plugin" is a plugin that is released for each release of SonarQube server. The GAV of this plugin is: org.codehaus.sonar:sonar-maven[3]-plugin. In the past we used to need 2 different plugins (one for Maven 2, one for Maven 3). It was the job of the "Codehaus Sonar Mojo" to bootstrap the correct one according to Maven version. Starting from SonarQube server 3.7 there is only one plugin: org.codehaus.sonar:sonar-maven-plugin. To not break compatibility with the "Codehaus Sonar Mojo" that will still need to bootstrap org.codehaus.sonar:sonar-maven3-plugin when you are using Maven 3+, then we have added a relocation pom at the old location.

As a sum up, here is what is expected when you start a SonarQube analysis with Maven 3+ and SonarQube server 3.7:

  1. mvn sonar:sonar
  2. Maven will download and use latest "Codehaus Sonar Mojo" ie org.codehaus.mojo:sonar-maven-plugin:2.1
  3. The "Codehaus Sonar Mojo" will query SonarQube server version and bootstrap org.codehaus.sonar:sonar-maven3-plugin:3.7
  4. Maven will download pom of org.codehaus.sonar:sonar-maven3-plugin:3.7 and see there is a relocation to org.codehaus.sonar:sonar-maven-plugin:3.7
  5. Maven will download and use org.codehaus.sonar:sonar-maven-plugin:3.7

After this introduction, back to your issue. The message show that the "Codehaus Sonar Mojo" is not able to download org.codehaus.sonar:sonar-maven3-plugin:3.7. First you should try Marc suggestion and try to update your Maven version in case there is a bug with relocation support (I saw nothing about this in Maven release notes). Then you should check your Maven configuration (are you using a repository manager?).

Finally if you still have an issue please start with a clean Maven repository (backup/remove ~/.m2/repository) then run mvn sonar:sonar -X and complete your question with full logs.

like image 95
Julien H. - SonarSource Team Avatar answered Sep 21 '22 01:09

Julien H. - SonarSource Team