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

  • Java Version : 1.7
  • ant version : 1.9
  • sonar-ant-task-2.2.jar
  • SonarQube Server : 7.5.0

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)
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Saurabh
  • 13
  • 5
  • Does this answer your question? [How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version](https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi) – sinclair Jul 21 '21 at 11:57
  • Thanks for the reply, I know how to solve this Major : Minor version error in general. What I am looking for is : Do we have any sonarscanner version for ANT project available compatible with Java 1.7 – Saurabh Jul 21 '21 at 11:59

3 Answers3

1

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/

Mohamed Anees A
  • 4,119
  • 1
  • 22
  • 35
  • Thanks for the reply.. please correct if my understanding is wrong. Sonar scanner scans the project and publish the report to sonarqube. In my case, its failing due to scanner. So, do we have any scanner version compatible with Java 1.7 – Saurabh Jul 21 '21 at 12:33
  • No @Saurabh. Even 1.8 is deprecated. You need to use 1.7 for building your project, and use 11 for executing sonarqube task. – Mohamed Anees A Jul 21 '21 at 12:43
  • Alternatively you can use Java 11 to build your project as long as your language level is set to Java 7 and you provide a Java 7 bootpath to avoid using later classes. In other words: yes, you can *target* Java 7 while still running your build with Java 11. – Joachim Sauer Jul 21 '21 at 12:55
  • Thanks...I will try this option. Thanks again..!! – Saurabh Jul 21 '21 at 13:02
0

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

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • its legacy project, so its bit challenging to upgrade, but will check. Thanks... – Saurabh Jul 21 '21 at 12:27
  • @Saurabh `you can have several Java versions in your machine` and use different version for sonarqube and your application – Ori Marko Jul 21 '21 at 12:29
0

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.

Saurabh
  • 13
  • 5