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

- 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
- [Coverage] Troubleshooting guide for .NET code coverage import - Clean Code / Guides - Sonar Community (sonarsource.com)
- SonarScanner-Troubleshooting(sonarqube.org)
- java - What are the -Xms and -Xmx parameters when starting JVM? - Stack Overflow
- Define variables - Azure Pipelines | Microsoft Learn
- Error in SonarCloudPrepare in Azure DevOps when no SONAR_SCANNER_OPTS set in version 1.8.0 and ScannerMode is CLI - SonarQube - Sonar Community (sonarsource.com)
Discover more from naiwaen@DebuggingSoft
Subscribe to get the latest posts sent to your email.



