8

My Scala project (Maven-managed) is failing to build on Travis, throwing a GC overhead limit exceeded error despite compiling fine locally with the same MAVEN_OPTS=-Xmx3g -XX:MaxPermSize=512m. I suspect that Travis is somehow ignoring my MAVEN_OPTS: When I try to test against Oracle JDK 8, Travis logs:

$ Setting environment variables from .travis.yml
$ export MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"

which looks good. However, soon after it logs:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0

which is troubling since NOWHERE am I specifying -XX:MaxPermSize=192m, only 512m. (This leads me to believe my -Xmx3g is also being ignored, causing the compilation failure.)

I tried specifying the MAVEN_OPTS in many additional places in my pom, to no avail. For example, for the maven-scala-plugin, I have:

<configuration>
  ...
  <jvmArgs>
    <jvmArg>-Xmx3g</jvmArg>
    <jvmArg>-XX:MaxPermSize=512m</jvmArg>
  </jvmArgs>
</configuration>

And I also have the following under the maven-surefire-plugin and scalatest plugin, though the build is failing during compilation not tests:

<configuration>
  <argLine>-Xmx3g -XX:MaxPermSize=512m</argLine>
</configuration>

The following is the entirety of my .travis.yml:

language: java
env:
  global:
    - MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"
script: mvn clean install
jdk:
    - oraclejdk8
    - oraclejdk7

I'm using Scala 2.11.2 and scala-maven-plugin 3.2.0.

4 Answers 4

9

UPDATE (11/2/15):

This was finally fully resolved here. Quoting:

If you want to use container-based builds (not relying on sudo), you can echo what you want into a $HOME/.mavenrc file and that will take precedence over /etc/mavenrc, like so:

in .travis.yml:

before_script:
  - echo "MAVEN_OPTS='-Xmx2g -XX:MaxPermSize=512m'" > ~/.mavenrc

(you could also put this in before_install depending on your setup).

Old answer:

I finally found the answer here, which references this (closed but not resolved) issue on the Travis CI github.

It seems like Travis exports a MAVEN_OPTS environment variable as root via the file /etc/mavenrc, which then does not get overridden by any other MAVEN_OPTS definitions (e.g. via env/global settings in the travis config). The workaround is to delete /etc/mavenrc before setting custom MAVEN_OPTS.

I was able to set custom MAVEN_OPTS and build successfully using the following in my .travis.yml:

script:
  - sudo rm /etc/mavenrc
  - export MAVEN_OPTS="-Xmx2469m -XX:MaxPermSize=512m"
  - mvn clean install

Note that I am NOT using language: java in my travis config, just calling maven directly via the script directive.

4
  • 1
    You probably want before_install, or before_script, to execute the echo command. You wouldn't want to completely replace script this way. Commented Dec 12, 2015 at 0:53
  • @CraigP.Motlin thanks, I think you're right, I edited my answer to use before_script rather than just script. In my case it doesn't really matter since I am replacing script anyway in order to compile using both maven and sbt. Could you elaborate on why it's bad to completely replace script? Commented Dec 14, 2015 at 17:35
  • 1
    It replaces the command which runs tests with the echo command. So the build basically sets the environment and exits. It would be ok if the command was something like echo ... && mvn ... Commented Dec 14, 2015 at 17:46
  • Similarly, Alpine Linux's Maven 3 package contains a /etc/mavenrc that sets the -Xmx param. There are probably other environments with this problem as well. Commented Mar 20, 2019 at 18:57
3

export MAVEN_SKIP_RC=true is the recommended way of doing this when dealing with a system that has an /etc/mavenrc. This will make it ignore the defaults and read the MAVEN_OPTS variable.

1

While it is possible to set -Xmx3g in Travis CI builds, its servers have limited memory to be free for JVM heap in forked surefire tests.

Here is project that use -Xmx2560m for max speed on Travis CI: https://github.com/plokhotnyuk/actors/blob/8f22977981e0c4d21b67beee994b339eb787ee9a/pom.xml#L151

You can check available memory by - sudo cat /proc/meminfo line added to .travis.yml. Here is output from some Travis CI build: https://travis-ci.org/plokhotnyuk/actors/jobs/55013090#L923

If your project requires bigger heap size then try https://www.shippable.com

Or it is better to use Wercker (much faster builds and without waiting in queue at all) http://wercker.com

5
  • Unfortunately this didn't work, I am still getting the same error, and the Java 8 build log is still saying 192m, though with the reduced memory my project still builds fine on my server. Commented Mar 23, 2015 at 14:36
  • @emma-strubell, it is possible to share your effective pom? Have you your code open-sourced? Commented Mar 25, 2015 at 7:29
  • Yes, the pom is here: github.com/strubell/factorie/blob/jflex-tokenization/pom.xml Commented Mar 27, 2015 at 14:44
  • In that pom both maven-surefire-plugin and scalatest-maven-plugin are enabled to run tests, and both of them can be configured with JVM options for forked tests by argLine argument. Commented Mar 27, 2015 at 19:48
  • Both plugins have argLine set, is there something else I should specify in the argLine? Commented Mar 27, 2015 at 23:29
0

This is what finally worked for me.

language: java
sudo: false
jdk:
  - oraclejdk8
install: MAVEN_SKIP_RC=true MAVEN_OPTS="-Xss4M" mvn install -DskipTests=true
script: MAVEN_SKIP_RC=true MAVEN_OPTS="-Xss4M" mvn

The MAVEN_SKIP_RC is needed as @adam says and the MAVEN_OPTS are what I needed to get javac to stop blowing out the stack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.