Increasing permgen space for Cobertura ant task running from Gradle - ant

I'm getting the following trying to run Cobertura as part of my Gradle build.
:cobertura
Instrumenting classes for Cobertura
Exception in thread "Test worker" java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space
I've tried bumping up DEFAULT_JVM_OPTS/-XX:MaxPermSize in my gradle wrapper script, to no effect. Is there a more direct (and effective) way to do this?

The only thing that worked for me was changing the .bashrc on my Linux box to have export _JAVA_OPTIONS='-XX:MaxPermSize=512m'
Proof that this got detected by gradle when I built was shown with this message:
Picked up _JAVA_OPTIONS: -XX:MaxPermSize=512m

Try to set a GRADLE_OPTS environment variable, or a org.gradle.jvmargs property in gradle.properties.

Related

Jenkins Gradle "Could not reserve enough space for object heap"

I'm trying to run a build task with Gradle on Jenkins, but Gradle fails to run.
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Parameter -Xmx2048m is apparently used in Java to run Gradle process.
If this parameter is the problem, where should I change it? (Jenkins is configured for -Xmx1024m). I'm running it on device with 1GB RAM (about 700 - 500MB free before running the task).
Full log: http://pastebin.com/BBsjp5pZ
I had to modify gradle.properties file in project folder
Original settings:
org.gradle.jvmargs=-Xmx2048m
New settings:
org.gradle.jvmargs=-Xmx512m -Xms100m
References:
Where should I put gradle.properties in Jenkins
https://docs.gradle.org/current/userguide/build_environment.html
The Jenkins manual talks about "GRADLE_OPTS".
Gradle build steps You can set the -Xmx or -XX:MaxPermSize by adding a
GRADLE_OPTS global environment variable in the Jenkins global
configuration. To do this, click Manage Jenkins, then Configure
System. In the Global properties section, click the Environment
Variables checkbox, then add a new environment variable called
GRADLE_OPTS with the value set appropriately, similar to the screen
shot above regarding MAVEN_OPTS

SonarRunner crashes due to Findbugs

I am doing a Sonar analysis of my project on a Jenkins Server using SonarRunner within an ant build. Unfortunately, the Analysis crashes with the following lines:
[sonar:sonar] 11:29:57.008 INFO - Execute Findbugs 2.0.3...
[sonar:sonar] 11:29:58.217 DEBUG - Release semaphore on project : org.sonar.api.resources.Project#5c1f0a26[id=3998,key=<key>,qualifier=TRK], with key batch-<key-batch>
[sonar:sonar] 11:29:58.247 DEBUG - To prevent a memory leak, the JDBC Driver [com.mysql.jdbc.Driver] has been forcibly deregistered
BUILD FAILED
<Path>: The following error occurred while executing this line:
<Path>: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
I have other projects running on the same server, which have no problem performing this analysis (and where the analysis is triggered exactly the same way). As you can see, I changed the log level to DEBUG, but, nevertheless, I get no stack trace and I am not able to find useful information in the logs of Jenkins or Sonar.
One other thing, I tried, was to increase the Heap space (with -Xmx) for this ant task in Jenkins but that didn't help either.
Are there any other settings I can take to get useful information or does somebody know about this problem?
Thanks!
Some more information could be useful. E.g.: what SonarQube and SonarRunner versions are you running.
Findbugs is one of the few analyzing plugins that need .class data for analyzing the project. So if you have not changed the directory within your build.xml the ant task may search within the default output folder location.
Please make sure your .class files are located here. To make them appear here you have to compile them before of course

Sonar analysis gives out of memory error, should I increase JVM heap space of Ant or Sonar server?

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
Navigate to your hudson job,
click Configure,
scroll down to the Build section, and
click the Advanced button.
Enter this into MAVEN_OPTS: -Xmx512m -XX:MaxPermSize=128m

Run sonar ant task using the command line - ClassDefNotFoundError

I'm trying to integrate custom PMD tasks in Sonar, which I currently managed to work along with Sonar PMD plugin.
My current issue is to run sonar ant task with the command line.
In my eclipse workspace, I add additional classpath entries in Eclipse for Ant to run and it works just fine.
But when i run it in the command line, no matter how I pass the jars for ant, it just doesn't seem to be using it in the ClassLoader.
This is a big issue for my project, once I can't put the task to run in my continuous integration server.
I'm currently passing the jar's that contains all the classes need using the property sonar.libraries.
The error I'm getting is:
build.xml:121: java.lang.NoClassDefFoundError: net/sourceforge/pmd/AbstractJavaRule
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
"sonar.libraries" references only dependencies of your application, not dependencies of Sonar execution context.
If you want to develop custom PMD tasks that will be used by Sonar, please have a look at this example plugin: https://github.com/SonarSource/sonar-examples/tree/master/plugins/sonar-pmd-extension-plugin
You just have to build the JAR of the plugin
Put it in your "/extensions/plugins" folder
And restart Sonar

Increasing maxHeap arg for Findbugs in Jenkins

I am running Findbugs with Ant with the <findbugs> task. I am running the Ant build.xml from Jenkins.
My build is stuck on low heap size : Exception in thread "main" java.lang.OutOfMemoryError: Java heap space.
I have read that I need to run Findbugs with -maxHeap n where n is the size (defaults to 256).
Since I am running Findbugs with Ant and running Ant from Jenkins, I don't really know where to pass this parameter. My options are :
Java Options in Jenkins Ant build step where I usually put parameters like -Xmx1024m -Xms512m etc...
As a jvmargs attribute to <findbugs> task in build.xml file.
I'm not exactly sure how to pass this parameter.
-maxHeap n is a parameter of the findbugs command line wrapper script and can only be used there.
To set the heap size from an ant script use the jvmargs attribute. So your second option should work. For example:
<findbugs output="xml" outputFile="..." jvmargs="-Xmx256m">
...
</findbugs>

Resources