Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3637

Introduce "sonar.java.jdkHome" to specify the JDK to be used by the analyzer to resolve JDK types

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.11
    • Component/s: Plugin, Semantic
    • Labels:
      None

      Description

      In the past behavior, the analyzer was relying on the runtime JDK to resolve JDK classes (prependBootClasspath option). A first improvement has been done in SONARJAVA-3056, to stop prepending bootclasspath when we find that rt.jar, jrt-fs.jar or android.jar are already passed in sonar.java.libraries. This is because SonarLint flavors recently started to pass those libraries paths.

      The problem of this approach is that it puts the responsibility to collect all JDK libs on each scanner/SonarLint. Since the logic is a bit tricky (depends on JDK flavor, version, OS), it would require a lot of duplication.

      The proposition is to move this logic directly into the analyzer. Scanners and SonarLint can simply provide the path to the JDK Home directory, using a new property sonar.java.jdkHome, and the analyzer will take care of "crawling" it to find the right JARs.

      The property need to be "resolved" per module on scanner side. For the moment, we don't support the case of a single module compiled with different JDKs.

      For backward compatibility, the property should not be mandatory.

      For SonarLint, it might be interesting to cache the list of JARs found for a given jdkHome in order to avoid crawling the FS for every on-the-fly analysis.

      See for example of how we get JAR list in SonarLint VSCode:
      https://github.com/SonarSource/sonarlint-language-server/blob/master/src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java
      More complex version (supporting very old JDKs):
      https://github.com/JetBrains/intellij-community/blob/83c8bf83bddbde6e4fa0d4ab6294a43387089e09/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              michael.gumowski Michael Gumowski
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: