全部学科
Python全栈
python
NodeJS全栈
nodejs
📅 2026-05-23 10 分钟 ✍️ juanwangdev

构建缓存与加速策略

CI/CD 缓存加速 Maven 构建。

GitHub Actions 缓存

YAML
- uses: actions/cache@v3
  with:
    path: ~/.m2/repository
    key: maven-${{ hashFiles('**/pom.xml') }}
    restore-keys: |
            maven-

GitLab CI 缓存

YAML
cache:
  paths:
    - .m2/repository/
variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

Jenkins 缓存

groovy
options {
  durabilityHint('PERFORMANCE_OPTIMIZED')
}
steps {
  sh 'mvn clean install -o'  // 离线模式使用缓存
}

要点总结

  • actions/cache GitHub Actions 缓存
  • cache paths GitLab CI 缓存
  • -o 离线模式使用缓存
  • MAVEN_OPTS 配置本地仓库路径
想在手机上练习这篇文章的配套题目?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码
← 上一篇 构建产物发布自动化
下一篇 → 依赖冲突诊断与解决
扫码体验小程序
加载中
想在手机上刷题学习?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码