Pages

Tuesday, November 30, 2010

Sonar Cobertura OutOfMemory Java Heap Size

When you configure and install the Sonar for to analyze and report metrics on source code, it sets the default code coverage tool as Cobertura. The "Maximum memory to pass to JVM of Cobertura processes" is defaulted to 64m. This max memory size is often too small for running sonar on big projects which generate large metrics.

Usually, it fails in the Collection phase of Cobertura with the "OutOfMemory Java Heap size" exception.

To fix this you will need increase the maxmem for the cobertura.

If you are using the Sonar web application for doing the settings then follow these steps:
1) Go to your Sonar Web applications' home page. it will be something like http://{your sonar host url}:9000
2) Go to Configuration >> Settings >> Cobertura.
3)  put 512m in the Maxmem field
4) Save it.
5) Now you need to stop and start your Sonar server for the changes to take effect.

6) Thats it! your OutOfMemory issue should be fixed now.

If you are doing the sonar settings in the maven pom files of your project then add following to your main/parent pom file


<project>
...<build>
...</build>
<properties>
    <cobertura.maxmem>512m</cobertura.maxmem>
</properties>
</project>

If above does not work for you then try this:

<project>
   ...
  <build>
     ...
     <plugins>
       ...
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>cobertura-maven-plugin</artifactId>
         <configuration>
           <maxmem>512m</maxmem>

         </configuration>
       </plugin>
     </plugins>
   </build>
</project>

I hope this helps.