I’ve installed sonarqube developer edition on ubuntu running on aws t3.medium, and configured my bitbucket cloud pipeline to run on pull request.
When the pipeline runs I get the following error. Can you please help?
ERROR: Error during SonarScanner execution
java.lang.OutOfMemoryError: Java heap space
I managed to make it work by analyzing some directories only. Locally I didn’t need to do that though
Welcome to the community!
It sounds like this is a question of the resources available on your build agent, especially if you didn’t have to make any exceptions/extra configurations
Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
Therefore you pretty much have two options:
Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)
Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program
Increasing the heap sizeis a bad solution, 100% temporary. It will crash again in somewhere else. To avoid these issues, write high performance code:
- Use local variables wherever possible.
- Make sure you select the correct object (EX: Selection between String, StringBuffer and StringBuilder)
- Use a good code system for your program(EX: Using static variables VS non static variables)
- Other stuff which could work on your code.
- Try to move with Multy Threading