Run cucumber test with cached dependencies and plugins on gradle

See this open Gradle issue

Gradle cache isn’t exactly portable currently. It does work, if the absolute path of the .gradle folder is exactly the same on both machines. The absolute path of ~/.gradle is not the same if the username on both machines is different!

There are a few ways you can get around this, in order of effort required, least to most:

1. Run without --offline once

If this is possible on your network limited machine, run without offline flag once, the dependencies will not be downloaded again, but checksums are – and more importantly the cache is now validated and suitable for use with the --offline flag.

2. Move .gradle to a repeatable path

Move gradle cache folder to something like /tmp/.gradle by setting GRADLE_USER_HOME on both machines and then copy gradle cache between machines.

3. Export all dependencies to a local folder

On the network connected machine, use a gradle task to export all dependencies to a filesystem folder. Copy the folder over to the other machine, and use a flatdir repo on the second machine.

repositories {
  flatDir {
    dirs 'lib' //folder containing dependencies
  }
}

(You could also export to a maven format repo instead of flatdir. See https://stackoverflow.com/a/13396776/1174024)

4. Use a maven cache instead

In my experience Maven’s .m2 folder is far more portable. Create a maven project with the same dependencies, cache dependencies into .m2 and then copy .m2 over to the second machine. On the second machine add mavenLocal() as a repo.

Leave a Comment