Saurabh
Saurabh

Reputation: 13

UnsupportedClassVersionError: org/sonar/api/utils/SonarException : Unsupported major.minor version 52.0

We have ANT based project running on Java 1.7 version, while integrating Sonar in this project, we are getting below error on "sonar : sonar" (Sonar scanner analysis) line in build.xml

I know the reason of below error, but do we have any sonarscanner version for ANT project available compatible with Java 1.7

Error:

java.lang.UnsupportedClassVersionError: org/sonar/api/utils/SonarException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

Upvotes: 0

Views: 451

Answers (3)

Saurabh
Saurabh

Reputation: 13

I resolved this issue by using maven only for the purpose of sonar scan. This way, I used sonar-maven-plugin to scan the legacy project. Existing ANT build tool is still used the way it was used earlier.

The reason we had to go with this option was that, the project is very old and upgrading JDK version or some other options would have taken significant amount of time.

  • Add pom.xml in your project by adding :

    org.codehaus.mojo sonar-maven-plugin 3.2
  • In the same pom.xml, you can define the other sonar properties.

  • run your project using command : mvn sonar:sonar

  • You will get the SONAR report.

Upvotes: 0

Mohamed Anees A
Mohamed Anees A

Reputation: 4601

As stated by @user7294900, Sonarqube analysis requires JDK 11 for performing code analysis.

Solution:

You can either migrate your codebase to version Java 11, or use multi JDK build. Build your code with JDK 7, and perform sonarqube task with JDK 11.

Steps for this is mentioned here,

https://docs.sonarqube.org/latest/analysis/analysis-with-java-11/

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58862

Even 6.7 version requires Java 8

The only prerequisite for running SonarQube is to have Java (Oracle JRE 8 or OpenJDK 8) installed on your machine.

So you should download Java 8 at least

  • you can have several Java versions in your machine

Also notice latest release requires Java 11

Java 11 is required for SonarQube scanners. Use of Java 8 is no longer supported

Upvotes: 0

Related Questions