Sonar 分析给出内存不足错误,我应该增加 Ant 还是 Sonar 服务器的 JVM 堆空间? [英] Sonar analysis gives out of memory error, should I increase JVM heap space of Ant or Sonar server?

查看:28
本文介绍了Sonar 分析给出内存不足错误,我应该增加 Ant 还是 Sonar 服务器的 JVM 堆空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Sonar 中分析一个大型项目并收到以下错误:

[sonar:sonar] 03:55:39.511 INFO p.PhasesTimeProfiler - 执行装饰器...构建失败[...][...] java.lang.OutOfMemoryError:Java 堆空间在 org.sonar.batch.index.MeasurePersister.model(MeasurePersister.java:127)在 org.sonar.batch.index.MeasurePersister.getMeasuresToSave(MeasurePersister.java:117)在 org.sonar.batch.index.MeasurePersister.dump(MeasurePersister.java:70)在 org.sonar.batch.index.DefaultPersistenceManager.dump(DefaultPersistenceManager.java:63)在 org.sonar.batch.phases.Phases.execute(Phases.java:95)在 org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:139)在 org.sonar.batch.bootstrap.Module.start(Module.java:83)在 org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:131)在 org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:121)在 org.sonar.batch.bootstrap.Module.start(Module.java:83)在 org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:121)在 org.sonar.batch.bootstrap.Module.start(Module.java:83)在 org.sonar.batch.Batch.execute(Batch.java:104)在 org.sonar.ant.Launcher.execute(Launcher.java:78)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.lang.reflect.Method.invoke(Method.java:616)在 org.sonar.ant.SonarTask.delegateExecution(SonarTask.java:244)在 org.sonar.ant.SonarTask.execute(SonarTask.java:193)在 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)在 sun.reflect.GeneratedMethodAccessor4.invoke(未知来源)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.lang.reflect.Method.invoke(Method.java:616)在 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)在 org.apache.tools.ant.Task.perform(Task.java:348)在 org.apache.tools.ant.Target.execute(Target.java:392)在 org.apache.tools.ant.Target.performTasks(Target.java:413)在 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)在 org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)在 org.apache.tools.ant.Project.executeTargets(Project.java:1251)在 org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)

我应该增加正在运行的 Sonar 服务器的 Java 堆空间,还是执行 Sonar 作业的 Ant 目标?

解决方案

从堆栈跟踪中可以看出,Ant 启动了 Sonar 分析,因此您应该为 Ant 运行的 VM 增加堆空间.

>

这是一个非常相似的问题顺便说一句:如何增加Sonar Java堆空间

对于命令行 Ant 使用

引用 Mark O'Connor 对另一个问题的回答:

<块引用>

Sonar ANT 任务作为 ANT 的一部分执行,因此您需要使用标准 ANT 环境参数设置 JVM 堆.例如:

导出 ANT_OPTS=-Xmx256m

备注:

  • 这是针对 Linux,对于 Windows,使用 set 命令
  • 这是严格的堆空间.对于 Permgen,使用 -XX:MaxPermSize=

这是一个更相似的问题:Build Failed java.lang.OutOfMemoryError: Java 堆空间

对于 Eclipse IDE

引自文章 http://soenkerohde.com/2008/06/change-eclipse-ant-settings-when-you-run-out-of-memory/

<块引用>
  • 在 Eclipse 打开菜单中:运行->外部工具->打开外部工具对话框...
  • 在左侧选择要更改的构建脚本
  • 选择右侧的 JRE 标签
  • 将以下内容设置为VM 参数:-Xms768m -Xmx1024m -XX:MaxPermSize=512m

对于 IntelliJ Idea

这个论坛帖子很有用:ANT build java heap space>

引用答案:

<块引用>

请确保您在正确的位置增加了堆.您需要在 IDEA 的 Ant 工具窗口中单击属性"按钮,然后在那里编辑最大堆大小 (Mb)" 字段.

此外,来自 IntelliJ Idea 页面:增加内存堆

引自文章:

<块引用>

构建过程的内存堆独立于IntelliJ IDEA内存堆,在构建过程完成后释放.

增加内存堆:打开构建文件属性对话框.在最大堆大小字段中,输入所需的内存量.

用于 Jenkins 持续集成和 Ant 构建

这个问题很有用:如何使用jenkins ant构建工具中的Java Options设置ANT_OPTS

引用答案:

<块引用>

仅将 JAVA OPTIONS 设置为 -Xmx512m -XX:MaxPermSize=256m,不带 ANT_OPTS=

对于Maven 构建,这篇文章很有用:如何在 hudson 构建中增加 Maven 堆空间

<块引用>

  1. 导航到您的哈德森工作,
  2. 点击配置
  3. 向下滚动到构建部分,然后
  4. 点击高级按钮.
  5. 将其输入到 MAVEN_OPTS: -Xmx512m -XX:MaxPermSize=128m

I am analysing a large project in Sonar and get the following error:

[sonar:sonar] 03:55:39.511 INFO  p.PhasesTimeProfiler - Execute decorators...

BUILD FAILED
[...]
[...] java.lang.OutOfMemoryError: Java heap space
at org.sonar.batch.index.MeasurePersister.model(MeasurePersister.java:127)
at org.sonar.batch.index.MeasurePersister.getMeasuresToSave(MeasurePersister.java:117)
at org.sonar.batch.index.MeasurePersister.dump(MeasurePersister.java:70)
at org.sonar.batch.index.DefaultPersistenceManager.dump(DefaultPersistenceManager.java:63)
at org.sonar.batch.phases.Phases.execute(Phases.java:95)
at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:139)
at org.sonar.batch.bootstrap.Module.start(Module.java:83)
at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:131)
at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:121)
at org.sonar.batch.bootstrap.Module.start(Module.java:83)
at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:121)
at org.sonar.batch.bootstrap.Module.start(Module.java:83)
at org.sonar.batch.Batch.execute(Batch.java:104)
at org.sonar.ant.Launcher.execute(Launcher.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.sonar.ant.SonarTask.delegateExecution(SonarTask.java:244)
at org.sonar.ant.SonarTask.execute(SonarTask.java:193)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)

Should I increase the java heap space of the running Sonar server, or the Ant target executing the Sonar job?

解决方案

As you can see from the stack trace, the Ant starts the Sonar analysis, so you should increase the heap space for the VM the Ant runs in.

This is a very similar question BTW: How to increase Sonar Java heap space

For command line Ant usage

Quote from the answer by Mark O'Connor on the other question:

The Sonar ANT task executes as part of ANT so you need to set the JVM heap using the standard ANT environment parameter. For example:

export ANT_OPTS=-Xmx256m

Remarks:

  • this is for Linux, for Windows, use the set command
  • this is strictly for the heap space. for Permgen, use -XX:MaxPermSize=<desired amount>

This is an even more similar question: Build Failed java.lang.OutOfMemoryError: Java heap space

For Eclipse IDE

Quote from the article http://soenkerohde.com/2008/06/change-eclipse-ant-settings-when-you-run-out-of-memory/

  • In Eclipse open menu: Run->External Tools->Open External Tools Dialog
  • Select the build script you want to change on the left
  • Select the JRE tab on the right
  • Set the following as VM arguments: -Xms768m -Xmx1024m -XX:MaxPermSize=512m

For IntelliJ Idea

This forum thread is useful: ANT build java heap space

Quote from the answers:

Please make sure that you increased heap in a correct place. You need to click 'Properties' button in IDEA's Ant tool window and edit 'Maximum heap size (Mb)' field there.

Also, from the IntelliJ Idea page: Increasing Memory Heap

Quote from the article:

The memory heap of the build process is independent of IntelliJ IDEA memory heap, and is released after the build process is complete.

To increase a memory heap: Open the Build File Properties dialog box. In the Maximum heap size field, type the required amount of memory.

For Jenkins Continuous Integration and Ant build

This question is useful : How to use the Java Options in jenkins ant build tool to set ANT_OPTS

Quote from the answer:

Set the JAVA OPTIONS as -Xmx512m -XX:MaxPermSize=256m only without the ANT_OPTS=

For Maven builds, this article is of use: How to increase maven heapspace in hudson builds

  1. Navigate to your hudson job,
  2. click Configure,
  3. scroll down to the Build section, and
  4. click the Advanced button.
  5. Enter this into MAVEN_OPTS: -Xmx512m -XX:MaxPermSize=128m

这篇关于Sonar 分析给出内存不足错误,我应该增加 Ant 还是 Sonar 服务器的 JVM 堆空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆