Gradle & Travis CI

Hello, I’m having trouble running gradle on travis ci.
I will start by saying the same gradle commands run fine on my macbook pro.
Details about the project:
JDK 8 oracle
Multi-project

Travis runs these 2 commands:
gradle assemble
gradle check
Both of them seems to output the same text locally and on Travis VM, but on Travis it suddenly fails:

$ gradle check
[/home/travis/build/1/2/3/src]
[/home/travis/build/1/2/3/test]
[/home/travis/build/0/1/5/src]
[/home/travis/build/0/1/5/test]
[/home/travis/build/0/1/4/src]
[/home/travis/build/0/1/4/test]
:4:compileJava UP-TO-DATE
:4:processResources UP-TO-DATE
:4:classes UP-TO-DATE
:4:jar UP-TO-DATE
:5:compileJava UP-TO-DATE
:5:processResources UP-TO-DATE
:5:classes UP-TO-DATE
:5:jar UP-TO-DATE
:3:compileJava UP-TO-DATE
:3:processResources UP-TO-DATE
:3:classes UP-TO-DATE
:3:compileTestJava
Download https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.pom
Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom
Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom
Download https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:3:processTestResources
:3:testClasses
:3:test FAILED
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:3:test’.

Process ‘Gradle Test Executor 1’ finished with non-zero exit value 137

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

So I changed the script to run
gradle assemble
gradle check --debug
And the result is attached below.
The first line is still a line my test printed to the console, later it suddenly fails

16:23:39.545 [DEBUG] [TestEventLogger] 30689
16:23:40.568 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
16:23:40.574 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process ‘Gradle Test Executor 1’ finished with exit value 137 (state: FAILED)
16:23:40.586 [DEBUG] [TestEventLogger]
16:23:40.587 [DEBUG] [TestEventLogger] Test Run PASSED
16:23:40.587 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ‘:2:test’
16:23:40.588 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :2:test FAILED
16:23:40.589 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :2:test (Thread[main,5,main]) completed. Took 20.59 secs.
16:23:40.589 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 41.881 secs, idle: 0.018 secs
16:23:40.605 [ERROR] [org.gradle.BuildExceptionReporter]
16:23:40.605 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter]
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ‘:2:test’.
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter] > Process ‘Gradle Test Executor 1’ finished with non-zero exit value 137
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter]
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
16:23:40.606 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
16:23:40.607 [LIFECYCLE] [org.gradle.BuildResultLogger]
16:23:40.607 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
16:23:40.607 [LIFECYCLE] [org.gradle.BuildResultLogger]
16:23:40.607 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 47.366 secs
16:23:40.608 [DEBUG] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopping 0 compiler daemon(s).
16:23:40.608 [INFO] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopped 0 compiler daemon(s).
16:23:40.608 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for settings file ‘/home/travis/build/0/1/settings.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/settings_b28kas7lah6wnh2vb3il7u0og/SettingsScript/buildscript).
16:23:40.608 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on no_buildscript class cache for settings file ‘/home/travis/build/0/1/settings.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/settings_b28kas7lah6wnh2vb3il7u0og/SettingsScript/no_buildscript).
16:23:40.609 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for build file ‘/home/travis/build/0/1/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_axqm1bna1fcdvw3x2gkv54wac/ProjectScript/buildscript).
16:23:40.609 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on no_buildscript class cache for build file ‘/home/travis/build/0/1/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_axqm1bna1fcdvw3x2gkv54wac/ProjectScript/no_buildscript).
16:23:40.609 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for build file ‘/home/travis/build/0/1/2/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_6wh1mhv7ftm2br6dsk1yfj7v/ProjectScript/buildscript).
16:23:40.609 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on no_buildscript class cache for build file ‘/home/travis/build/0/1/2/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_6wh1mhv7ftm2br6dsk1yfj7v/ProjectScript/no_buildscript).
16:23:40.609 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for build file ‘/home/travis/build/0/1/5/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_7yy0sjvqcfmelr7bac2r9u5ma/ProjectScript/buildscript).
16:23:40.610 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on no_buildscript class cache for build file ‘/home/travis/build/0/1/5/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_7yy0sjvqcfmelr7bac2r9u5ma/ProjectScript/no_buildscript).
16:23:40.610 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for build file ‘/home/travis/build/0/1/4/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_1d6735qorxdm3f84qayxu4n8e/ProjectScript/buildscript).
16:23:40.612 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on no_buildscript class cache for build file ‘/home/travis/build/0/1/4/build.gradle’ (/home/travis/.gradle/caches/2.2.1/scripts/build_1d6735qorxdm3f84qayxu4n8e/ProjectScript/no_buildscript).
16:23:40.620 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache fileHashes.bin (/home/travis/build/0/1/.gradle/2.2.1/taskArtifacts/fileHashes.bin)
16:23:40.621 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache fileSnapshots.bin (/home/travis/build/0/1/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin)
16:23:40.621 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache outputFileStates.bin (/home/travis/build/0/1/.gradle/2.2.1/taskArtifacts/outputFileStates.bin)
16:23:40.621 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache taskArtifacts.bin (/home/travis/build/0/1/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin)
16:23:40.622 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on task history cache (/home/travis/build/0/1/.gradle/2.2.1/taskArtifacts).
16:23:40.622 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on cache directory workerMain (/home/travis/.gradle/caches/2.2.1/workerMain).
16:23:40.632 [DEBUG] [org.gradle.cache.internal.DefaultCacheAccess] Cache Plugin Resolution Cache (/home/travis/.gradle/caches/2.2.1/plugin-resolution) was closed 0 times.
16:23:40.632 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache artifact-at-repository.bin (/home/travis/.gradle/caches/modules-2/metadata-2.14/artifact-at-repository.bin)
16:23:40.632 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache module-artifacts.bin (/home/travis/.gradle/caches/modules-2/metadata-2.14/module-artifacts.bin)
16:23:40.633 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache module-metadata.bin (/home/travis/.gradle/caches/modules-2/metadata-2.14/module-metadata.bin)
16:23:40.633 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache artifact-at-url.bin (/home/travis/.gradle/caches/modules-2/metadata-2.14/artifact-at-url.bin)
16:23:40.633 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on artifact cache (/home/travis/.gradle/caches/modules-2).
16:23:40.634 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.store.CachedStoreFactory] Resolution result cache closed. Cache reads: 0, disk reads: 0 (avg: 0.0 secs, total: 0.0 secs)
16:23:40.634 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.store.CachedStoreFactory] Resolved configuration cache closed. Cache reads: 0, disk reads: 0 (avg: 0.0 secs, total: 0.0 secs)
16:23:40.634 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.store.ResolutionResultsStoreFactory] Deleted 2 resolution results binary files in 0.001 secs
16:23:40.635 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedRepositoryFactory] In-memory dependency metadata cache closed. Repos cached: 5, cache instances: 1, modules served from cache: 171, artifacts: 167

Do any of your tests use Swing or require a running window manager?

This usually indicates a SIGKILL being issued by TravisCI due to high memory use or a build taking too long.

1 Like

Thank you, high memory was really the issue and as suggested here , stopping some services I don’t need - fixed the issue.
This is what I added to my .travis.yml

before_script:

  • sudo service postgresql stop || true
  • sudo service mysql stop || true
  • sudo service memcached stop || true
  • sudo service bootlogd stop || true
  • sudo service elasticsearch stop || true
  • sudo service mongodb stop || true
  • sudo service neo4j stop || true
  • sudo service cassandra stop || true
  • sudo service riak stop || true
  • sudo service rsync stop || true
  • sudo service x11-common stop || true

Note: I suppose it’s possible to narrow this list down to one problematic service.

1 Like

I think, this only works, if sudo: true is enabled, which is not the new container-based infrastructure.

For the container based infrastructure the problem is (in my case) that the initial heap size is too big. See this other post for a way to solve this.

The solution by @hirscheran works here. One has to use the Trusty environment. Example .travis.yml is available at https://github.com/JabRef/jabref/blob/e7455ee/.travis.yml

@sherter Could you provide a deep link for “this other post”?

I’ve already provided a pretty deep link, just klick on “a way to solve this” :wink:

The CSS should be improved though. Links are really hard to spot in this forum!

I had a similar issue:
Process 'Gradle Test Executor 2' finished with non-zero exit value 137

I did not try to stop services as suggested by @hirscheran, since my build runs on a container with sudo: false and I didn’t want to change that.

As @sherter suggested, the problem is that GradleRunner forks processes which end up taking too much memory, then Travis kills them.

What solved the problem for me was reducing max heap size of forked gradle processes run by GradleRunner.
This can be done like this:

GradleRunner.create()
.withJvmArguments("-Xmx128m")
...
build()

Notice that the method withJvmArguments is not defined on the GradleRunner abstract class, but is defined on the DefaultGradleRunner object which is returned from GradleRunner.create(). So if your code is Java, you’ll have to cast. If your code is Groovy you are fine without casting.

@Doron_Gold Please be aware that the method GradleRunner.withJvmArguments is an internal method and might change anytime. That’s why it’s currently not exposed through the interface. You should be able to achieve the same by setting up a gradle.properties files with an entry of org.gradle.jvmargs alongside the build.gradle file under test.

@bmuschko Thanks for the tip. I followed your suggestion and it works.

It could be even better if putting org.gradle.daemon.idletimeout=0 in gradle.properties had effect. Seems like it does not have effect because daemonMaxIdleTime is set to 120 seconds in a hardcoded fashion under org.gradle.testkit.runner.internal.ToolingApiGradleExecutor.
Setting a low idletimeout for the Daemons spawned by GradleRunner is a better solution for conserving memory than just limiting the max memory of each daemon.