我们正在尝试为我们的Android构建工作流程缓存所有gradle依赖项
这是当前失败的方法
restore_cache:
key: android-build-{{ checksum "android/build.gradle" }}-{{ checksum "android/app/build.gradle" }}
save_cache:
paths:
- ~/.gradle
key: android-build-{{ checksum "android/build.gradle" }}-{{ checksum "android/app/build.gradle" }}
答案 0 :(得分:1)
有一个示例Android配置by Circle CI themselves here以及属性的分步演练。
version: 2
jobs:
build:
working_directory: ~/code
docker:
- image: circleci/android:api-25-alpha
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
# - run:
# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
# command: sudo chmod +x ./gradlew
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Run Tests
command: ./gradlew lint test
- store_artifacts:
path: app/build/reports
destination: reports
- store_test_results:
path: app/build/test-results
值得注意的是,由于子模块使用缓存时我们遇到了一些问题,但上述内容适用于更简单的存储库。
答案 1 :(得分:1)
在restore_cache
和save_cache
之间放置构建步骤。
如果您的项目是多模块/级别的,则散列所有构建脚本,并将其用作正确捕获依赖项的键:
- run:
name: Hash dependency info
command: |
mkdir -p build
md5sum gradle.properties settings.gradle build.gradle **/build.gradle >build/deps.md5
- restore_cache:
key: gradle-{{ checksum "build/deps.md5" }}
- run:
name: Build and deploy
command: >
bash ./gradlew
build artifactoryPublish
- save_cache:
key: gradle-{{ checksum "build/deps.md5" }}
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper