Java maven build completes successfully but .m2 local repository is not getting cached

Hi All,

I am using following travis configuration for our project. But it doesn’t cache the local .m2 directory after a successful build. Because of this, Our build exceeds the execution time limit (50min) and get failed.

language: java
sudo: true
# Can't update to xenial distribution (ubuntu 16.04) bause of the Java JDK restriction (Not supporting )
dist: trusty

# Using -q Quiet output which only show errors, to overcome TravisCI log limit issue
script: mvn clean install -Dmaven.test.skip -q -B -V | grep -v DEBUG; exit "${PIPESTATUS[0]}";

cache:
  directories:
   - $HOME/.m2
   - /home/travis/build/wso2/carbon-apimgt/features/apimgt/org.wso2.carbon.apimgt.publisher.feature/src/main/resources/publisher-new/node_modules
   - /home/travis/build/wso2/carbon-apimgt/features/apimgt/org.wso2.carbon.apimgt.store.feature/src/main/resources/store-new/node_modules

Can you please help me to figure out why the .m2 directory is not getting cached? Is there anything wrong with the above configuration which prevents caching the directories.

Thanks
~Kasun

Ahh sorry, Builds is public,
Here is the link
https://travis-ci.org/wso2/carbon-apimgt
sample build which failed due to exceeding the time limit
https://travis-ci.org/wso2/carbon-apimgt/builds/563456939

You are using exit in your script. User commands are executed in the worker bash process with eval, so exit quits this process and terminates your build before it reaches the cache stage.

https://docs.travis-ci.com/user/job-lifecycle/#complex-build-commands mentions this but it’s not prominent at all. You can use “improve this page on Github” links in documentation to add this information more prominently where you expect it to be (e.g. maybe in https://docs.travis-ci.com/user/common-build-problems/) to warn your next of kin – and yourself after you forget this in a few months.

Use e.g. test $code -eq 0 to make the last command in script return success or failure depending on previously saved exit code. Or (exit $?) (run exit in subprocess) to return that code directly.


If your build takes longer than Travis’ job time limit, use a stage to warm up the cache: https://docs.travis-ci.com/user/build-stages/warm-cache/

Judging by https://stackoverflow.com/questions/35944964/maven-pre-download-all-dependencies , mvn dependency:go-offline will pre-download all dependencies to cache without building.

Related:

Hi @native-api,

Thank you very much for your help. It worked after removing the exit command from the script. And as you suggested I have updated the common-build-problems.md documentation and here is the PR1.

Please review and merge.

Thanks
~Kasun

Imprint