sonar maven plugin build error, SonarQube version: null

22,442

Solution 1

For those interested in "why?", I've done some more digging and what seems to be happening is this:

This sq-version.txt file is located in org.codehaus.sonar:sonar-plugin-api, but this dependency is not included (even transitively) in the sonar-maven-plugin. All it references sonar-wise is org.sonarsource.sonar-runner:sonar-runner-api.

They seem to have changed the location and name of the version txt file but not updated all code. You might get away with manually adding an sq-version.txt with content 5.2 (no newline) to the plugin classpath (possibly by updating the plugin jar), or add a dependency on sonar-plugin-api, but these are hacks.

The sonar-maven-plugin 2.6 uses sonar-runner 2.4, which is very different from 2.5 that sonar-maven-plugin 2.7 uses (the groupId for sonar-runner has changed domains from org.codehaus.sonar.runner to org.sonarsource.sonar-runner), so it's best to stick to the v2.6 plugin until they have smoothed out the transition and released a few more versions.

Solution 2

Solved by downgrading the automatically picked latest (2.7) version to an older one (2.4) by adding this code to the plugins section of my pom.xml

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>2.4</version>
  </plugin>

Solution 3

The way SonarQube server version is passed to maven-sonar-plugin has changed in v2.7, along with other things, since it uses now sonar-runner 2.5.

There is indeed a bug when using it with SonarQube instances < 4.3, for which I opened the ticket: https://jira.sonarsource.com/browse/MSONAR-131

Note that SQs < 4.5 (current LTS) are no longer actively supported and there is no guarantee that sonar-maven-plugin won't be incompatible with them in other ways due to the new interface exposed by sonar-runner 2.5.

For these cases, it is probably best to lock the maven plugin version to 2.6, as already suggested.

Solution 4

We had the same problem at work today, we automatically use the latest version for maven and sonar plugins. It wasn't easy to find the problem at first.

The answer elcodedocle has given is correct, but i would like to add for those that use maven with sonar in an automated fashion that this is a solution aswell:

org.codehaus.mojo:sonar-maven-plugin:2.6:sonar

This way it runs on the older version 2.6 and i can confirm that it works.

There is probably a bug in 2.7 and i hope it gets fixed soon. This was our error:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven plugin:2.7:sonar (default-cli) on project (projectName): Unable to determine structure of project. Probably you use Maven Advanced Reactor Options with a broken tree of modules. "(projectName)" is orphan -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

EDIT: Take a look at this post for some more information: Jenkins Sonar plugin suddenly stops working

Here is explained that the new version, 2.7, of the plugin is no longer compatible with java 6 projects. You can also find an explanation about how to fix it in Jenkins if you are not familiar with it. (my explanation was a bit short)

Share:
22,442
NotGaeL
Author by

NotGaeL

None of the opinions expressed on the content I post here necessarily reflect the opinions of my employers (or my current ones). The dumb ones are probably sarcastic. https://abstrusegoose.com/249

Updated on July 05, 2022

Comments

  • NotGaeL
    NotGaeL almost 2 years

    My jenkins builds just started to fail with this message:

    [INFO] --- sonar-maven-plugin:2.7:sonar (default-cli) @ cividas-core-web ---
    [INFO] artifact com.ontimize:ontimize-core: checking for updates from central
    [INFO] artifact com.ontimize:ontimize-core: checking for updates from imatia-local
    [INFO] artifact com.ontimize:ontimize-core: checking for updates from snapshots
    [INFO] User cache: /var/lib/jenkins/.sonar/cache
    [INFO] SonarQube version: null
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.773s
    [INFO] Finished at: Thu Oct 22 19:49:04 CEST 2015
    [INFO] Final Memory: 13M/193M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project cividas-core-web: null: MojoExecutionException: NullPointerException -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project cividas-core-web: null
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        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:317)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    Caused by: org.apache.maven.plugin.MojoExecutionException
        at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
        at org.codehaus.mojo.sonar.bootstrap.RunnerBootstrapper.execute(RunnerBootstrapper.java:107)
        at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:141)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
    Caused by: java.lang.NullPointerException
        at org.apache.maven.artifact.versioning.ComparableVersion.parseVersion(ComparableVersion.java:354)
        at org.apache.maven.artifact.versioning.ComparableVersion.<init>(ComparableVersion.java:345)
        at org.apache.maven.artifact.versioning.DefaultArtifactVersion.parseVersion(DefaultArtifactVersion.java:110)
        at org.apache.maven.artifact.versioning.DefaultArtifactVersion.<init>(DefaultArtifactVersion.java:46)
        at org.codehaus.mojo.sonar.bootstrap.RunnerBootstrapper.isVersionPriorTo5Dot2(RunnerBootstrapper.java:192)
        at org.codehaus.mojo.sonar.bootstrap.RunnerBootstrapper.execute(RunnerBootstrapper.java:84)
        ... 22 more
    [ERROR] 
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    Sonar analysis completed: FAILURE
    

    What is this all about?

  • Kaitsu
    Kaitsu over 8 years
    For us, the 2.7 version of the sonar-maven-plugin fails the same way as well, but works with version 2.6. Any idea what is the reason?
  • domi
    domi over 8 years
    see this if you use jenkins to trigger it: stackoverflow.com/a/33297231/187950
  • Yves Martin
    Yves Martin over 8 years
    I would say that the server does not send the version back. As far as I understand, the Sonarqube server version is queried thanks to "BatchIsolatedRunner.getVersion" github.com/SonarSource/sonar-runner/blob/master/…
  • Aaron Digulla
    Aaron Digulla over 8 years
    Quite possible. I don't have a local setup, so I can't debug ATM.
  • Ash Ash
    Ash Ash almost 8 years
    I am using the following versions. I have also tried mentioning the version in the goal, but still getting the issue. SonarQube: v 4.5.1 , java: v 1.7.0 , sonar-maven-plugin : 3.0.2 ( default ). Have also tried mentioning older version in the goal as : org.sonarsource.scanner.maven:sonar-maven-plugin:2.0.6:sonar