9

我正在使用 Maven site:run 生成 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)
4

2 回答 2

15

在你的 pom.xml 中使用这个属性:

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

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

</project>
于 2010-02-18T10:46:59.910 回答
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 插件属性

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

尝试使用 fork 或通过以下方式增加内存。我不确定它是否适用于 cobertura,但似乎适用于 junit。此页面的片段:

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

或者

<plugin>
...
<configuration>
...
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine> 
</configuration>
</plugin>
于 2010-01-12T12:21:19.063 回答