9

I am using Maven site:run to generate a cobertura code coverage...

The following is my pom.xml configuration for cobertura:

<reporting>
    ...
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
</reporting>

However I am getting OutOfMemoryError at the end of the site:run. Please suggest how to get rid of this error. (I have tried all those -Xmx, -XX options...)

Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space
        at sun.reflect.GeneratedSerializationConstructorAccessor74.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.io.ObjectStreamClass.newInstance(ObjectStreamClass.java:924)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1737)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at java.util.HashMap.readObject(HashMap.java:1030)
        at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:480)
        at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObject(CoverageDataContainer.java:373)
        at sun.reflect.GeneratedMethodAccessor348.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at java.util.HashMap.readObject(HashMap.java:1030)
        at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
KrishPrabakar
  • 2,824
  • 2
  • 31
  • 44

2 Answers2

15

Use this property in your pom.xml :

<project>
...
<build>
...
</build>

<properties>
    <cobertura.maxmem>256M</cobertura.maxmem>
</properties>

</project>
Jean-Philippe Briend
  • 3,455
  • 29
  • 41
1

Did you try something like export MAVEN_OPTS=-Xmx1024m (Or the highest value that match your machine)?

If you still don't have enough memory to run maven, then I would suggest you try to disable other plugin and exclude some classes from the test coverage to check if it's really a memory issue.

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>cobertura-maven-plugin</artifactId>
 <configuration>
  <instrumentation>
    <ignores>
      <ignore>com.example.boringcode.*</ignore>
    </ignores>
    <excludes>
      <exclude>com/example/dullcode/**/*.class</exclude>
      <exclude>com/example/**/*Test.class</exclude>
    </excludes>
  </instrumentation>
</configuration>

http://mojo.codehaus.org/cobertura-maven-plugin/usage.html

EDIT

Other ideas:

Set the following properties (see the cobertura plugin properties)

-Dmaven.cobertura.report.maxmemory=xxx
-Dmaven.cobertura.instrumentation.maxmemory=xxx

Try to use fork or increase the memory with the following. I'm not sure whether it works for cobertura, but seem to work for junit. Snippet from this page:

<plugin>
...
<configuration>
<forkMode>pertest</forkMode>
</configuration>
</plugin>

or

<plugin>
...
<configuration>
...
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine> 
</configuration>
</plugin>
ewernli
  • 38,045
  • 5
  • 92
  • 123
  • This is my MAVEN_OPTS: -XX:MaxPermSize=512m -Xms128m -Xmx600m (I changed it to -Xmx1024m but I got the following error: Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.) – KrishPrabakar Jan 12 '10 at 12:32
  • Hi ewernli, I tried but still issue exists... this is the change I did it in pom.xml: (I excluded the biggest packages) com/xxx/**/*Test.class com/xxx/yyy/rating/**/*.class com/xxx/yyy/common/**/*.class – KrishPrabakar Jan 19 '10 at 10:21
  • I got it! Adding 512m in pom.xml resolved my issue. Thanks everyone! – KrishPrabakar Feb 19 '10 at 08:52