6

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 

4 Answers 4

10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot.. The problem indeed was that Maven was not able to download org.codehaus.sonar:sonar-maven3-plugin:3.7. After that, it correctly relocated to org.codehaus.sonar:sonar-maven-plugin:3.7. It works fine now.
@Abby, what exactly did you need to do to make it work? Upgrade Maven?
@Julien I'm having a similar problem; looks like SonarQube can't download the plugin in step 2. I'm getting "Failure to find org.codehaus.sonar:sonar-maven3-plugin:jar:5.2". Any ideas on how to troubleshoot this?
1

I had the same problem. I was using mvn sonar:sonar, which after an upgrade from Sonar 3.1 to 3.7 failed with exactly the same error message.

Turns out I was using an old version of Maven (3.0.1), which I guess did not handle this relocation of plugins correctly. Upgrading to Maven 3.0.5 fixed the problem for me.

Comments

1

I have looked into pom file for sonar-maven3-plugin and looks like it has been relocated to sonar-maven-plugin

http://repo1.maven.org/maven2/org/codehaus/sonar/sonar-maven3-plugin/3.7/sonar-maven3-plugin-3.7.pom

pom says

Since Sonar 3.7 there is no more difference between Maven 2 and Maven 3 so relocate to Maven 2 plugin to avoid duplication 

so I guess you can use sonar-maven-plugin instead of sonar-maven3-plugin.

2 Comments

How do I specify that? All I do is mention version 2.1 in maven-plugin version in jenkins. I tries to look up org.codehaus.mojo.sonar-maven-plugin.2.1 which it finds and then tries executing the goal, after which I get the above exception.
Don't be confused. There is no sonar-maven2-plugin and you should not try to use other plugin than org.codehaus.mojo:sonar-maven-plugin. See my answer for details.
0

not sure if my diagnose is correct but it looks like:

  • you used sonar some time ago so your maven downloaded all the plugins
  • later they relocated some of their plugins so your downloaded plugins don't reflect the structure they expect right now (sounds ridiculous and exactly opposite to how maven supposed to work)

for me it helped to delete ~/.m2/repository/org/codehouse/mojo/sonar-maven-plugin and ~/.m2/repository/org/codehouse/... something else with sonar (i don't remember exactly)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.