As far as I can see, currently cache supports only caching of files inside current directory (or by absolute path). But Gradle places it's caches inside ~/.gradle directory. Currently I had tried:
We run the caching outside the build container. So you can cache absolute paths, but since only /builds and /cache is transferred you have no-way to cache container-local files.
You need to relocate your container-local directory (like: /root/.cabal, /root/.gradle) to /cache. If you put that in /cache you don't need to use the cache in .gitlab-ci.yml directive then, since this is already preserved between builds.
I'll create separate document to describe this behavior in details and possible solutions.
Caching is currently the best to use to cache files stored in your build directory.
For the sake of helping anyone else who wonders what is the recipe for some other popular package managers, here it is.
Bower
Create a new .bowerrc file with:
{ "storage":{ "packages": ".bower-cache/" }}
Npm
Create a new .npmrc file with:
cache=.node-cache
Composer
In the composer.json file, set:
{ "config": { "cache-dir": ".composer-cache" }}
gitlab-ci.yml file
Personally I like to use the global cache statement and override the key, so each build on any branch hit the cache. Just realize that the cache may grow over time...