Sonar - OutOfMemoryError: Java heap space

后端 未结 8 2342
情话喂你
情话喂你 2021-02-07 02:07

I am deploying a large Java project on Sonar using \"Findbugs\" as profile and getting the error below:

Caused by: java.util.concurrent.ExecutionException: java.         


        
8条回答
  •  抹茶落季
    2021-02-07 02:49

    I had the same problem and found a very different solution, perhaps because I'm having a hard time swallowing the previous answers / comments. With 10 million lines of code (that's more code than is in an F16 fighter jet), if you have a 100 characters per line (a crazy size), you could load the whole code base into 1GB of memory. I set it 8GB of memory and it still failed. Why?

    Answer: Because the community Sonar C++ scanner seems to have a bug where it picks up ANY file with the letter 'c' in its extension. That includes .doc, .docx, .ipch, etc. Hence, the reason it's running out of memory is because it's trying to read some file that it thinks is 300mb of pure code but really it should be ignored.

    Solution: Find the extensions used by all of the files in your project (see more here):

    dir /s /b | perl -ne 'print $1 if m/\.([^^.\\\\]+)$/' | sort -u | grep c
    

    Then add these other extensions as exclusions in your sonar.properties file:

    sonar.exclusions=**/*.doc,**/*.docx,**/*.ipch
    

    Then set your memory limits back to regular amounts.

    %JAVA_EXEC% -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m %SONAR_RUNNER_OPTS% ...
    

提交回复
热议问题