Sonar - OutOfMemoryError: Java heap space

后端 未结 8 2344
情话喂你
情话喂你 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:35

    You can solve this issue by increase the maximum memory allocated to the appropriate process by increasing the -Xmx memory setting for the corresponding Java process in your sonar.properties file

    under SonarQube/conf/sonar.properties

    uncomment below lines and increase the memory as you want:

    For Web: Xmx5123m -Xms1536m -XX:+HeapDumpOnOutOfMemoryError
    For ElasticSearch: Xms512m -Xmx1536m -XX:+HeapDumpOnOutOfMemoryError
    For Compute Engine: sonar.ce.javaOpts=-Xmx1536m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
    
    0 讨论(0)
  • 2021-02-07 02:43

    this has worked for me:

    SONAR_RUNNER_OPTS="-Xmx3062m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m"
    

    I set it direct in the sonar-runner(.bat) file

    0 讨论(0)
  • 2021-02-07 02:45

    I had the same problem when running sonar with maven. In my case it helped to call sonar separately:

    mvn clean install && mvn sonar:sonar

    instead of

    mvn clean install sonar:sonar

    http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven

    Remark: Because my solution is connected to maven, this is not the direct answer for the question. But it might help other users who stumple upon it.

    0 讨论(0)
  • 2021-02-07 02:48

    The problem is on FindBugs side. I suppose you're analyzing a large project that probably has many violations. Take a look at two threads in Sonar's mailing list having the same issue. There are some ideas you can try for yourself.

    http://sonar.15.n6.nabble.com/java-lang-OutOfMemoryError-Java-heap-space-td4898141.html

    http://sonar.15.n6.nabble.com/java-lang-OutOfMemoryError-Java-heap-space-td5001587.html

    0 讨论(0)
  • 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% ...
    
    0 讨论(0)
  • 2021-02-07 02:49

    What you can do it to create your own quality profile with just some Findbugs rules at first, and then progressively add more and more until you reach his OutOfMemoryError. There's probably only a single rule that makes all this fail because your code violates it - and if you deactivate this rule, it will certainly work.

    0 讨论(0)
提交回复
热议问题