Maven Cobertura OutOfMemoryError

时间:2010-01-12 11:55:09

标签: maven-2 maven out-of-memory cobertura

我正在使用Maven站点:运行以生成cobertura代码覆盖...

以下是我对cobertura的pom.xml配置:

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

但是我在网站末尾得到OutOfMemoryError:运行。请建议如何摆脱这个错误。 (我已经尝试了所有这些-Xmx,-XX选项......)

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)

2 个答案:

答案 0 :(得分:15)

在pom.xml中使用此属性:

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

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

</project>

答案 1 :(得分:1)

您是否尝试过export MAVEN_OPTS=-Xmx1024m(或与机器匹配的最高值)?

如果你仍然没有足够的内存来运行maven,那么我建议你尝试禁用其他插件并从测试覆盖中排除一些类来检查它是否真的是内存问题。

<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

修改

其他想法:

设置以下属性(请参阅cobertura plugin properties

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

尝试使用fork或使用以下内容增加内存。我不确定它是否适用于cobertura,但似乎适用于junit。来自此page

的代码段
<plugin>
...
<configuration>
<forkMode>pertest</forkMode>
</configuration>
</plugin>

<plugin>
...
<configuration>
...
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine> 
</configuration>
</plugin>