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]}";

   - $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/

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.


Ahh sorry, Builds is public,
Here is the link
sample build which failed due to exceeding the time limit

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. 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 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:

Judging by , mvn dependency:go-offline will pre-download all dependencies to cache without building.


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 documentation and here is the PR1.

Please review and merge.