Cannot perform SonarQube analysis from Jenkins

I am trying to tune Jenkins Sonarqube analysis (using Maven). I have Sonarqube 3.7 installed. I have set up a Jenkins sonar plugin and it works well. I have Maven 3.0.3 and I am using the sonar maven 2.1 plugin.

The problem is that it tries to fulfill the goal, but asks org.codehaus.sonar: sonar-maven3-plugin: jar: 3.7. I can not find this jar anywhere. In repositories, I can also just see what pom is, not 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 
+6
source share
4 answers

Do not confuse. There are 2 different plugins.

The first is what we call "Sonar Mojo." This is what you call when you run mvn sonar:sonar . GAV of this plugin: org.codehaus.mojo:sonar-maven-plugin We recently released version 2.1 to support Maven 3.1. There is no private release of this plugin because we try to avoid any connection with the SonarQube version. When you call this plugin, it will just perform some basic checks, ask the SonarQube server about its version, and then bootstrap the “SonarQube Maven plugin”.

The "SonarQube Maven plugin" is a plugin released for each version of the SonarQube server. GAV of this plugin: org.codehaus.sonar:sonar-maven[3]-plugin . We used to have to use two different plugins (one for Maven 2, one for Maven 3). It was the work of “Sonar Mojoh Codeh” to download the correct version according to the Maven version. Starting with the SonarQube 3.7 server, there is only one plugin: org.codehaus.sonar:sonar-maven-plugin . In order not to break the compatibility with the "Codehaus Sonar Mojo", which org.codehaus.sonar:sonar-maven3-plugin still needs to download when you use Maven 3+, we have added the transfer hyphenation to the same place.

As a result, this is what is expected when you start analyzing SonarQube with Maven 3+ and SonarQube 3.7 servers:

  • mvn sonar:sonar
  • Maven will download and use the latest "Codehaus Sonar Mojo", i.e. org.codehaus.mojo:sonar-maven-plugin:2.1
  • "Codehaus Sonar Mojo" will request the version of the SonarQube server and bootstrap org.codehaus.sonar:sonar-maven3-plugin:3.7
  • Maven will load pom from org.codehaus.sonar:sonar-maven3-plugin:3.7 and see that there is a move to org.codehaus.sonar:sonar-maven-plugin:3.7
  • Maven will download and use org.codehaus.sonar:sonar-maven-plugin:3.7

After this introduction, return to your problem. The message shows that "Codehaus Sonar Mojo" cannot load org.codehaus.sonar:sonar-maven3-plugin:3.7 . First you should try Marc suggestion and try to upgrade the version of Maven in case there is a bug with support for moving (I did not see anything about this in the Maven release notes). Then you should check your Maven configuration (do you use storage manager?).

Finally, if you still have a problem, start with a clean Maven repository (backup / remove ~ / .m2 / repository), then run mvn sonar:sonar -X and fill out your question with full logs.

+10
source

I looked at the pom file for sonar-maven3-plugin and seems to have been ported 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 

therefore, I think you can use the sonar-maven-plugin instead of the sonar-maven3-plugin.

+1
source

I had the same problem. I used mvn sonar:sonar , which, after upgrading from Sonar 3.1 to 3.7, could not get the exact same error message.

It turns out that I used the old version of Maven (3.0.1), which, I think, could not handle this moving plugins correctly. Upgrading to Maven 3.0.5 fixed the problem for me.

+1
source

Not sure if my diagnosis is correct, but it looks like this:

  • you used sonar some time ago, so your maven downloaded all the plugins
  • they later moved some of their plugins so that your loaded plugins do not display the structure they are expecting right now (sounds funny and exactly the opposite of how maven should work).

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

0
source

Source: https://habr.com/ru/post/953549/


All Articles