简体   繁体   English

GitHub 操作:在 Windows 环境中缓存 Maven.m2 存储库 C\:\\Users\runneradmin\\.m2\repository: Cannot stat: No such file or directory

[英]GitHub Actions: Cache Maven .m2 repository on Windows environment C\:\\Users\runneradmin\\.m2\repository: Cannot stat: No such file or directory

As the docs state in order to cache the Maven dependencies with GitHub Actions all we have to use is the actions/cache action like this: 作为文档 state为了使用 GitHub Actions 缓存 Maven 依赖项,我们必须使用如下操作/缓存操作:

steps:
  - uses: actions/checkout@v2
  - name: Set up JDK 1.8
    uses: actions/setup-java@v1
    with:
      java-version: 1.8
  - name: Cache Maven packages
    uses: actions/cache@v2
    with:
      path: ~/.m2
      key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
      restore-keys: ${{ runner.os }}-m2
  - name: Build with Maven
    run: mvn --batch-mode --update-snapshots verify

However using the windows-2016 GitHub Actions environment, this doesn't provides us with a working cache - as the logs states :但是使用windows-2016 GitHub Actions 环境,这并没有为我们提供工作缓存 - 正如日志所述

Post job cleanup.
"C:\Program Files\Git\usr\bin\tar.exe" --posix --use-compress-program "zstd -T0" -cf cache.tzst -P -C D:/a/spring-boot-admin/spring-boot-admin --files-from manifest.txt --force-local
/usr/bin/tar: C\:\\Users\runneradmin\\.m2\repository: Cannot stat: No such file or directory
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Tar failed with error: The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2

How to fix this?如何解决这个问题?

It seems that the path to the Maven repository isn't correctly initialized.似乎 Maven 存储库的路径未正确初始化。 As this issue describes the paths are written with \\ instead of / which GNU tar expects.正如这个问题所描述的那样,路径是用\\而不是 GNU tar 期望的/编写的。 The fix was already provided in Dec 2020 , so it made it to the version v2.1.4 .该修复程序已在 2020 年 12 月提供,因此已发布到v2.1.4版本。 The last version v2.1.3 was released in November.最后一个版本v2.1.3于 11 月发布。 But sadly there is a bug in pointing the v2 to the latest v2.1.4 (as normally expected by GitHub Actions users).但遗憾的是,在将v2指向最新的 v2.1.4 时存在一个v2.1.4 (正如 GitHub Actions 用户通常所期望的那样)。 Therefore to solve this issue, we need to explicitely specifiy the full actions/cache version v2.1.4 like this:因此,为了解决这个问题,我们需要像这样明确指定完整的操作/缓存版本v2.1.4

steps:
  - uses: actions/checkout@v2
  - name: Set up JDK 1.8
    uses: actions/setup-java@v1
    with:
      java-version: 1.8
  - name: Cache Maven packages
    uses: actions/cache@v2.1.4
    with:
      path: ~/.m2
      key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
      restore-keys: ${{ runner.os }}-m2
  - name: Build with Maven
    run: mvn --batch-mode --update-snapshots verify

Now it should work like a charm ( see logs here ).现在它应该像魅力一样工作( 请参阅此处的日志)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM