[SonarQube] Fixed Exception in thread “Report about progress of Java XML analyzer” java.lang.OutOfMemoryError: Java heap space

Problem

  • หลังจากลองให้ SonarQube import test coverage report แล้วพบ Error
Exception in thread “Report about progress of Java XML analyzer” java.lang.OutOfMemoryError: Java heap space
  • อ๋อ และถ้าใครใช้ภาษาอื่นๆที่ไม่ใช่ java อย่าง .NET ตัว มันเจอ Error นี้นะ หลีกเลี่ยงไม่ได้

Solution

กำหนด Memory ให้ Sonar Scanners เพิ่ม โดยแก้ Environment Variable SONAR_SCANNER_OPTS และกำหนดค่า Xmx ซึ่งเจ้าค่า Xmx = maximum memory allocation pool ของ JAVA ครับ สำหรับการแก้ไขในแต่ละ Environment มี ดังนี้

  • Windows Agents
set SONAR_SCANNER_OPTS=-Xmx4096m
หรือ กำหนดผ่าน GUI ของ Windows ก็ได้ครับ ^__^
  • Linux Agents
export SONAR_SCANNER_OPTS="-Xmx4096m"
  • Azure DevOps - กำหนดใน YAML กำหนด SONAR_SCANNER_OPTS ใน Azure Pipeline
trigger:
- master

stages:
- stage: Build
  jobs:
  - job: Build
    pool:
      vmImage: 'windows-2019'

    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
      SONAR_SCANNER_OPTS: '-Xmx4096m'
    steps: .....

NOTE: จากที่ลองมา ตัวเลย 512MB ตามที่ Official Doc แนะนำมาไม่เพียงพอ อย่างของผมกำหนดเป็น 4096MB เลย เพราะขนาด Project ใหญ่มากๆ แต่อย่าลืมตรวจสอบ RAM ที่เครื่องที่ Run Sonar Scanner ด้วยนะ ว่าเพียงพอไหม

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.