Run cucumber test with cached dependencies and plugins on gradle

时光怂恿深爱的人放手 提交于 2019-12-17 14:55:23

问题


Hi I want to run a few test made with cucumber on a gradle project, I was trying to run this test's on another PC (with limited network access) so I copy/pasted everything that was under ~./gradle/caches and the project files like build, src and build.gradle and placed everything on the same place as the original

So once I got everything in place I ran this

  gradle --no-daemon --offline cucumber

And I get a failure

> Could not resolve all dependencies for configuration ':classpath'.
   > Could not download gradle-cucumber-plugin.jar (com.github.samueltbrown:gradle-cucumber-plugin:0.9): No cached version available for offline mode

The odd thing is that I have the file on the caches directory

~/.gradle/caches/modules-2/files-2.1/com.github.samueltbrown/gradle-cucumber-plugin/0.9/7b65c67654715025eed1924
0c4f7defbef9645e0# ls
gradle-cucumber-plugin-0.9.jar

FYI, I don't have the kind of experience with gradle/java as I would like so any kind of suggestion would be great, this is where the plugin is "required" on the build.gradle

plugins {
  id "com.github.samueltbrown.cucumber" version "0.9"
}

Thanks


回答1:


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.



来源:https://stackoverflow.com/questions/34968042/run-cucumber-test-with-cached-dependencies-and-plugins-on-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!