使用缓存的依赖项和gradle上的插件运行黄瓜测试

时间:2023-01-17 12:43:16

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

嗨我想在gradle项目上运行一些用黄瓜做的测试,我试图在另一台PC(有限的网络访问)上运行此测试,所以我复制/粘贴了〜。/ gradle / caches和项目下的所有内容像build,src和build.gradle这样的文件,并将所有内容放在与原始文件相同的位置

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

仅供参考,我没有像gradle / java那样的经验,所以任何建议都会很棒,这就是build.gradle上“必需”的插件

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

Thanks

谢谢

1 个解决方案

#1


3  

See this open Gradle issue

请参阅此打开的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!

Gradle缓存当前不是完全可移植的。如果.gradle文件夹的绝对路径在两台机器上完全相同,它确实有效。如果两台机器上的用户名不同,〜/ .gradle的绝对路径就不一样了!

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.

如果在您的网络受限计算机上可以执行此操作,则在没有脱机标志的情况下运行一次,将不会再次下载依赖项,但校验和是 - 更重要的是,缓存现在已经过验证并且适合与--offline标志一起使用。

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.

通过在两台计算机上设置GRADLE_USER_HOME,然后在计算机之间复制gradle缓存,将gradle缓存文件夹移动到/tmp/.gradle之类的内容。

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.

在网络连接的计算机上,使用gradle任务将所有依赖项导出到文件系统文件夹。将文件夹复制到另一台计算机,并在第二台计算机上使用flatdir repo。

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

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

(您也可以导出为maven格式的repo而不是flatdir。请参阅https://*.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.

根据我的经验,Maven的.m2文件夹更加便携。创建具有相同依赖项的maven项目,将依赖项缓存到.m2中,然后将.m2复制到第二台机器上。在第二台机器上添加mavenLocal()作为repo。

#1


3  

See this open Gradle issue

请参阅此打开的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!

Gradle缓存当前不是完全可移植的。如果.gradle文件夹的绝对路径在两台机器上完全相同,它确实有效。如果两台机器上的用户名不同,〜/ .gradle的绝对路径就不一样了!

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.

如果在您的网络受限计算机上可以执行此操作,则在没有脱机标志的情况下运行一次,将不会再次下载依赖项,但校验和是 - 更重要的是,缓存现在已经过验证并且适合与--offline标志一起使用。

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.

通过在两台计算机上设置GRADLE_USER_HOME,然后在计算机之间复制gradle缓存,将gradle缓存文件夹移动到/tmp/.gradle之类的内容。

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.

在网络连接的计算机上,使用gradle任务将所有依赖项导出到文件系统文件夹。将文件夹复制到另一台计算机,并在第二台计算机上使用flatdir repo。

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

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

(您也可以导出为maven格式的repo而不是flatdir。请参阅https://*.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.

根据我的经验,Maven的.m2文件夹更加便携。创建具有相同依赖项的maven项目,将依赖项缓存到.m2中,然后将.m2复制到第二台机器上。在第二台机器上添加mavenLocal()作为repo。