在 gradle 上使用缓存的依赖项和插件运行黄瓜测试 [英] Run cucumber test with cached dependencies and plugins on gradle
问题描述
我想在一个 gradle 项目上运行一些用黄瓜做的测试,我试图在另一台 PC 上运行这个测试(网络访问受限),所以我复制/粘贴了 下的所有内容~./gradle/caches
和 build, src 和 build.gradle
等项目文件,并将所有内容放在与原始文件相同的位置
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
我失败了
> 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
仅供参考,我没有像我希望的那样使用 gradle/java 的经验,所以任何类型的建议都会很棒,这是 build.gradle 上需要"插件的地方
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"
}
谢谢
推荐答案
看到这个开放的 Gradle issue
Gradle 缓存目前并不完全可移植.如果 .gradle 文件夹的绝对路径在两台机器上完全相同,它确实有效.如果两台机器的用户名不同,~/.gradle
的绝对路径是不一样的!
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:
如果这在您的网络受限机器上是可能的,在没有离线标志的情况下运行一次,将不会再次下载依赖项,但校验和 - 更重要的是缓存现在已经过验证并适合与 一起使用 -离线
标志.
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.
通过在两台机器上设置 GRADLE_USER_HOME
将 gradle 缓存文件夹移动到类似 /tmp/.gradle
的位置,然后在机器之间复制 gradle 缓存.
Move gradle cache folder to something like /tmp/.gradle
by setting GRADLE_USER_HOME
on both machines and then copy gradle cache between machines.
在联网的机器上,使用 gradle 任务将所有依赖项导出到文件系统文件夹.将文件夹复制到另一台机器上,并在第二台机器上使用 flatdir 存储库.
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
}
}
(您也可以导出到 maven 格式的存储库而不是 flatdir.参见 https://stackoverflow.com/a/13396776/1174024)
(You could also export to a maven format repo instead of flatdir. See https://stackoverflow.com/a/13396776/1174024)
根据我的经验,Maven 的 .m2 文件夹更便携.创建一个具有相同依赖项的 maven 项目,将依赖项缓存到 .m2 中,然后将 .m2 复制到第二台机器上.在第二台机器上添加 mavenLocal()
作为 repo.
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.
这篇关于在 gradle 上使用缓存的依赖项和插件运行黄瓜测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!