Java heap space error during gradle build

When running a gradle build in TeamCity I'm getting the following error when compiling test sources:

FAILURE: Build failed with an exception.  *

What went wrong:

Execution failed for task ':compileTestGroovy'. > Java heap space  *

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I've tried bumping up the available heap space by adding "-Xmx2g" the "JVM command line parameters" setting, but the error still occurs.  What is the correct way to increase heap space for a build?  Also, it's worth noting that the build completes without error if I run the equivalent gradle commands from the command prompt on the server running the build agent.

2 comments
Comment actions Permalink

Hi Mark,

The "JVM command line parameters" is used to configure maximum heap size. For more details please see: https://confluence.jetbrains.com/display/TCD9/Gradle#Gradle-JavaParameters.
What TeamCity version do you use? When you run build on agent machine via command line, did you run it under the same user that the agent is running, with the same environment variables and the same working directory?
Please try to use a command line runner in TeamCity to launch the same command as in the console. Does it work?
Have you tried to run the build with --stacktrace option?

0
Comment actions Permalink

We are using TeamCity Enterprise 8.0.5

I was able to fix the problem by specifying heap space settings in the gradle script itself.  Here is the code:

tasks.withType(GroovyCompile) {
    configure(groovyOptions.forkOptions) {
        memoryMaximumSize = '1g'
        
jvmArgs = ['-XX:MaxPermSize=512m', '-Xms512m', '-Xmx1g']
    }
}


I'm guessing the problem was that the JVM parameters specified in TeamCity don't affect the process doing the compiling because it's forked.

0

Please sign in to leave a comment.