8

Our Jenkins builds started failing overnight with the error:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project <project>: 
Execution default-cli of goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar failed: 
Unable to load the mojo 'sonar' in the plugin 'org.codehaus.mojo:sonar-maven-plugin:2.7' due to an API incompatibility:
org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/codehaus/mojo/sonar/SonarMojo :
Unsupported major.minor version 51.0

The Jenkins server is still running Java 6, but we did not change anything.

What happened and how do we fix it?

Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189

1 Answers1

25

The jenkins-sonar-plugin uses sonar-maven-plugin to run the Sonar analysis.

Sonar-maven-plugin was updated to 2.7 on 2015-10-19 and the new version is not compatible with Java 6.

Jenkins-sonar-plugin uses the latest version of sonar-maven-plugin per default, but you can override this.

So to fix the error, open "Manage Jenkins"/"Configure System", find the Sonar section, click advanced and enter 2.6 in "Version of sonar-maven-plugin". This forces jenkins-sonar-plugin to use the previous version of sonar-maven-plugin, which works with Java 6.

Alternatively, if you want to set 2.6 only for one specific Jenkins job then you can force maven to use 2.6 version using goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar instead of standard sonar:sonar.

Also: begin planning to upgrade the build server to Java 7 or Java 8.

Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
  • 1
    And as mentioned in [this post](http://stackoverflow.com/a/31394509/2999457) and on [oracle](http://www.oracle.com/technetwork/java/javase/compatibility-417013.html), "The class file version for Java SE 7 is 51" hence the `Unsupported major.minor version 51.0` – lazi74 Nov 05 '15 at 09:48
  • The link to override the sonar-maven-plugin is not working. Can you please update it? – NewUser Nov 27 '15 at 09:15
  • @NewUser: I did not add that link myself, so I do not know what it contained. Anyway, the next paragraph explains how to override the setting. – Rasmus Faber Nov 27 '15 at 09:38
  • Thanks. :) The solution you have provided works absolutely fine, If you can accept this as solution it will be better... – NewUser Nov 27 '15 at 09:39
  • I am getting a NullPointerException '[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project sip-internal-impl-parent: null: MojoExecutionException: NullPointerException -> [Help 1]' @Rasmus, I am using all the latest versions. I have also tried mentioning the version in the goal, but still getting the issue. Here are the versions that i am using : SonarQube: v 4.5.1 , java: v 1.7.0 , sonar-maven-plugin : 2.6 & 3.0.2. – Ash Ash Jun 07 '16 at 13:39
  • @AshAsh: Then it is an entirely different problem. You should create a new question with as much information (including the full stacktrace) as you can provide. – Rasmus Faber Jun 07 '16 at 13:53
  • Have found a post which deals with the issue that i am facing here http://stackoverflow.com/questions/33287641/sonar-maven-plugin-build-error-sonarqube-version-null/33386209#33386209 – Ash Ash Jun 07 '16 at 13:59