Travis CI ignoring MAVEN_OPTS?

依然范特西╮ 提交于 2019-11-30 19:29:34

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!