web-dev-qa-db-ja.com

Gitlab CI Gradle依存関係キャッシュ

私はAndroidをビルドしていて、毎回依存関係をダウンロードするのは面倒です。キャッシュを試しました:

$HOME/.gradle/
$HOME/.gradle/caches/
$GRADLE_HOME/caches/
$HOME/.m2/
.gradle/
build/
app/build/

私の.gitlab-ci.ymlの26594番目の反復は here です。ビルド環境にgradleをインストールしたのは、gradlewをキャッシュしないと毎回ダウンロードされるため、さらに時間がかかるためです。私が構築に使用する画像は here です。私のCIサーバーの起動スクリプトは here にあります。キャッシュが機能する場合、ビルドごとにダウンロードする依存関係のリストは表示されないと思います。

ビルドログ:

gitlab-ci-multi-runner 0.7.2(998cf5d)画像でDocker executorを使用するAndroid ... Dockerイメージをプルするgitlab/gitlab-runner:build ... DockerイメージをプルするAndroid:latest ...警告:画像の最新バージョンをプルできませんAndroid:latest:エラー:画像ライブラリ/ Android:latestが見つかりません警告:ローカルで見つかった画像が代わりに使用されます.

Running on runner-76acd9d3-project-74192-concurrent-0 via ff9200d4be41...
Fetching changes...
Removing .gradle/
Removing artifacts.upload.log
Removing rxfirebaseandroid/build/
HEAD is now at 7f151df djgfj
Checking out 7f151df2 as ci-gitlab...
HEAD is now at 7f151df... djgfj
Restoring cache...

$ gradle testDebug
Download https://jcenter.bintray.com/com/Android/tools/build/gradle/1.3.0/gradle-1.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/build/gradle-core/1.3.0/gradle-core-1.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/build/builder/1.3.0/builder-1.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/lint/lint/24.3.0/lint-24.3.0.pom
Download https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/5.2.1/proguard-gradle-5.2.1.pom
Download https://jcenter.bintray.com/net/sf/proguard/proguard-parent/5.2.1/proguard-parent-5.2.1.pom
Download https://jcenter.bintray.com/com/Android/tools/build/builder-model/1.3.0/builder-model-1.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/build/builder-test-api/1.3.0/builder-test-api-1.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/sdklib/24.3.0/sdklib-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/sdk-common/24.3.0/sdk-common-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/common/24.3.0/common-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/build/manifest-merger/24.3.0/manifest-merger-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/ddms/ddmlib/24.3.0/ddmlib-24.3.0.pom
Download https://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom
Download https://jcenter.bintray.com/org/sonatype/oss/oss-parent/7/oss-parent-7.pom
Download https://jcenter.bintray.com/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.pom
Download https://jcenter.bintray.com/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm/5.0.3/asm-5.0.3.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm-parent/5.0.3/asm-parent-5.0.3.pom
Download https://jcenter.bintray.com/org/ow2/ow2/1.3/ow2-1.3.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.pom
Download https://jcenter.bintray.com/com/Android/tools/jack/jack-api/0.9.0/jack-api-0.9.0.pom
Download https://jcenter.bintray.com/com/Android/tools/jill/jill-api/0.9.0/jill-api-0.9.0.pom
Download https://jcenter.bintray.com/com/Android/tools/lint/lint-checks/24.3.0/lint-checks-24.3.0.pom
Download https://jcenter.bintray.com/org/Eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.pom
Download https://jcenter.bintray.com/net/sf/proguard/proguard-base/5.2.1/proguard-base-5.2.1.pom
Download https://jcenter.bintray.com/com/Android/tools/annotations/24.3.0/annotations-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/layoutlib/layoutlib-api/24.3.0/layoutlib-api-24.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/dvlib/24.3.0/dvlib-24.3.0.pom
Download https://jcenter.bintray.com/com/google/code/gson/gson/2.2.4/gson-2.2.4.pom
Download https://jcenter.bintray.com/org/Apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.pom
Download https://jcenter.bintray.com/org/Apache/commons/commons-parent/33/commons-parent-33.pom
Download https://jcenter.bintray.com/org/Apache/apache/13/Apache-13.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpcomponents-client/4.1.1/httpcomponents-client-4.1.1.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/project/4.1.1/project-4.1.1.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpmime/4.1/httpmime-4.1.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpcomponents-client/4.1/httpcomponents-client-4.1.pom
Download https://jcenter.bintray.com/com/google/guava/guava/17.0/guava-17.0.pom
Download https://jcenter.bintray.com/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom
Download https://jcenter.bintray.com/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.pom
Download https://jcenter.bintray.com/com/Android/tools/lint/lint-api/24.3.0/lint-api-24.3.0.pom
Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.pom
Download https://jcenter.bintray.com/com/intellij/annotations/12.0/annotations-12.0.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpcore/4.1/httpcore-4.1.pom
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpcomponents-core/4.1/httpcomponents-core-4.1.pom
Download https://jcenter.bintray.com/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download https://jcenter.bintray.com/org/Apache/commons/commons-parent/5/commons-parent-5.pom
Download https://jcenter.bintray.com/org/Apache/apache/4/Apache-4.pom
Download https://jcenter.bintray.com/commons-codec/commons-codec/1.4/commons-codec-1.4.pom
Download https://jcenter.bintray.com/org/Apache/commons/commons-parent/11/commons-parent-11.pom
Download https://jcenter.bintray.com/com/Android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.pom
Download https://jcenter.bintray.com/com/Android/tools/build/gradle/1.3.0/gradle-1.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/build/gradle-core/1.3.0/gradle-core-1.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/build/builder/1.3.0/builder-1.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/lint/lint/24.3.0/lint-24.3.0.jar
Download https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/5.2.1/proguard-gradle-5.2.1.jar
Download https://jcenter.bintray.com/com/Android/tools/build/builder-model/1.3.0/builder-model-1.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/build/builder-test-api/1.3.0/builder-test-api-1.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/sdklib/24.3.0/sdklib-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/sdk-common/24.3.0/sdk-common-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/common/24.3.0/common-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/build/manifest-merger/24.3.0/manifest-merger-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/ddms/ddmlib/24.3.0/ddmlib-24.3.0.jar
Download https://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0.jar
Download https://jcenter.bintray.com/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar
Download https://jcenter.bintray.com/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar
Download https://jcenter.bintray.com/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar
Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar
Download https://jcenter.bintray.com/com/Android/tools/jack/jack-api/0.9.0/jack-api-0.9.0.jar
Download https://jcenter.bintray.com/com/Android/tools/jill/jill-api/0.9.0/jill-api-0.9.0.jar
Download https://jcenter.bintray.com/com/Android/tools/lint/lint-checks/24.3.0/lint-checks-24.3.0.jar
Download https://jcenter.bintray.com/org/Eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.jar
Download https://jcenter.bintray.com/net/sf/proguard/proguard-base/5.2.1/proguard-base-5.2.1.jar
Download https://jcenter.bintray.com/com/Android/tools/annotations/24.3.0/annotations-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/layoutlib/layoutlib-api/24.3.0/layoutlib-api-24.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/dvlib/24.3.0/dvlib-24.3.0.jar
Download https://jcenter.bintray.com/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
Download https://jcenter.bintray.com/org/Apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpmime/4.1/httpmime-4.1.jar
Download https://jcenter.bintray.com/com/google/guava/guava/17.0/guava-17.0.jar
Download https://jcenter.bintray.com/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar
Download https://jcenter.bintray.com/com/Android/tools/lint/lint-api/24.3.0/lint-api-24.3.0.jar
Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.jar
Download https://jcenter.bintray.com/com/intellij/annotations/12.0/annotations-12.0.jar
Download https://jcenter.bintray.com/org/Apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar
Download https://jcenter.bintray.com/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
Download https://jcenter.bintray.com/commons-codec/commons-codec/1.4/commons-codec-1.4.jar
Download https://jcenter.bintray.com/com/Android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.jar
Download https://jcenter.bintray.com/com/firebase/firebase-client-Android/2.3.1/firebase-client-Android-2.3.1.pom
Download https://jcenter.bintray.com/io/reactivex/rxjava/1.0.14/rxjava-1.0.14.pom
Download https://jcenter.bintray.com/com/firebase/firebase-client-jvm/2.3.1/firebase-client-jvm-2.3.1.pom
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-databind/2.2.2/jackson-databind-2.2.2.pom
Download https://jcenter.bintray.com/com/fasterxml/oss-parent/10/oss-parent-10.pom
Download https://jcenter.bintray.com/com/firebase/tubesock/0.0.11/tubesock-0.0.11.pom
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-annotations/2.2.2/jackson-annotations-2.2.2.pom
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-core/2.2.2/jackson-core-2.2.2.pom
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-annotations/2.2.2/jackson-annotations-2.2.2.jar
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-core/2.2.2/jackson-core-2.2.2.jar
Download https://jcenter.bintray.com/com/fasterxml/jackson/core/jackson-databind/2.2.2/jackson-databind-2.2.2.jar
Download https://jcenter.bintray.com/com/firebase/tubesock/0.0.11/tubesock-0.0.11.jar
Download https://jcenter.bintray.com/com/firebase/firebase-client-jvm/2.3.1/firebase-client-jvm-2.3.1.jar
Download https://jcenter.bintray.com/com/firebase/firebase-client-Android/2.3.1/firebase-client-Android-2.3.1.jar
Download https://jcenter.bintray.com/io/reactivex/rxjava/1.0.14/rxjava-1.0.14.jar
Download https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom
Download https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom
Download https://jcenter.bintray.com/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom
Download https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
Download https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar
:rxfirebaseandroid:preBuild UP-TO-DATE
:rxfirebaseandroid:preDebugBuild UP-TO-DATE
:rxfirebaseandroid:checkDebugManifest
:rxfirebaseandroid:prepareDebugDependencies
:rxfirebaseandroid:compileDebugAidl UP-TO-DATE
:rxfirebaseandroid:compileDebugRenderscript UP-TO-DATE
:rxfirebaseandroid:generateDebugBuildConfig UP-TO-DATE
:rxfirebaseandroid:generateDebugAssets UP-TO-DATE
:rxfirebaseandroid:mergeDebugAssets UP-TO-DATE
:rxfirebaseandroid:generateDebugResValues UP-TO-DATE
:rxfirebaseandroid:generateDebugResources UP-TO-DATE
:rxfirebaseandroid:packageDebugResources UP-TO-DATE
:rxfirebaseandroid:processDebugManifest UP-TO-DATE
:rxfirebaseandroid:processDebugResources UP-TO-DATE
:rxfirebaseandroid:generateDebugSources UP-TO-DATE
:rxfirebaseandroid:processDebugJavaRes UP-TO-DATE
:rxfirebaseandroid:compileDebugJavaWithJavac UP-TO-DATE
:rxfirebaseandroid:preDebugUnitTestBuild UP-TO-DATE
:rxfirebaseandroid:prepareDebugUnitTestDependencies
:rxfirebaseandroid:processDebugUnitTestJavaRes UP-TO-DATE
:rxfirebaseandroid:compileDebugUnitTestJavaWithJavac UP-TO-DATE
:rxfirebaseandroid:compileDebugUnitTestSources UP-TO-DATE
:rxfirebaseandroid:mockableAndroidJar UP-TO-DATE
:rxfirebaseandroid:assembleDebugUnitTest UP-TO-DATE
:rxfirebaseandroid:testDebugUnitTest UP-TO-DATE

BUILD SUCCESSFUL

Total time: 51.086 secs
$ gradle assembleDebug
:rxfirebaseandroid:compileLint
:rxfirebaseandroid:copyDebugLint UP-TO-DATE
:rxfirebaseandroid:preBuild UP-TO-DATE
:rxfirebaseandroid:preDebugBuild UP-TO-DATE
:rxfirebaseandroid:checkDebugManifest
:rxfirebaseandroid:prepareDebugDependencies
:rxfirebaseandroid:compileDebugAidl UP-TO-DATE
:rxfirebaseandroid:compileDebugRenderscript UP-TO-DATE
:rxfirebaseandroid:generateDebugBuildConfig UP-TO-DATE
:rxfirebaseandroid:generateDebugAssets UP-TO-DATE
:rxfirebaseandroid:mergeDebugAssets UP-TO-DATE
:rxfirebaseandroid:generateDebugResValues UP-TO-DATE
:rxfirebaseandroid:generateDebugResources UP-TO-DATE
:rxfirebaseandroid:packageDebugResources UP-TO-DATE
:rxfirebaseandroid:processDebugManifest UP-TO-DATE
:rxfirebaseandroid:processDebugResources UP-TO-DATE
:rxfirebaseandroid:generateDebugSources UP-TO-DATE
:rxfirebaseandroid:processDebugJavaRes UP-TO-DATE
:rxfirebaseandroid:compileDebugJavaWithJavac UP-TO-DATE
:rxfirebaseandroid:extractDebugAnnotations UP-TO-DATE
:rxfirebaseandroid:mergeDebugProguardFiles UP-TO-DATE
:rxfirebaseandroid:packageDebugJar UP-TO-DATE
:rxfirebaseandroid:compileDebugNdk UP-TO-DATE
:rxfirebaseandroid:packageDebugJniLibs UP-TO-DATE
:rxfirebaseandroid:packageDebugLocalJar UP-TO-DATE
:rxfirebaseandroid:packageDebugRenderscript UP-TO-DATE
:rxfirebaseandroid:bundleDebug UP-TO-DATE
:rxfirebaseandroid:compileDebugSources UP-TO-DATE
:rxfirebaseandroid:assembleDebug UP-TO-DATE

BUILD SUCCESSFUL

Total time: 10.146 secs

Archiving cache...
INFO[0000] Creating archive cache.tgz ...               
INFO[0002] Done!                                        
Archiving artifacts...
INFO[0000] Creating archive artifacts.tgz ...           
INFO[0000] Done!                                        
Uploading artifacts...
20.0K   artifacts.tgz

Build succeeded.
17
DariusL

https://stackoverflow.com/a/35478988/2026105

別の投稿がこれに対する答えを持っていることがわかりました!回避策として、before_scriptを実行してGRADLE_HOMEをプロジェクトのディレクトリに設定し、キャッシュディレクティブを使用してSlurpできます。

before_script:
    - export GRADLE_USER_HOME=`pwd`/.gradle

cache:
  paths:
     - .gradle/wrapper
     - .gradle/caches

build:
  stage: build
  script:
     - ./gradlew assemble

test:
  stage: test
  script:
     - ./gradlew check
44
ETL

KamilTrzciński によると

ビルドコンテナーの外部でキャッシュを実行します。したがって、絶対パスをキャッシュできますが、/ buildsと/ cacheのみが転送されるため、コンテナローカルファイルをキャッシュする方法がありません。

それはあなたがgradleファイルを例えばに置く必要があることを意味します。 /cacheフォルダ

before_script:
  - export GRADLE_USER_HOME=cache/.gradle

...

cache:
  key: "$CI_COMMIT_REF_NAME" #optional: per branch caching, can be omitted
  paths:
    - $GRADLE_USER_HOME/caches/
    - $GRADLE_USER_HOME/wrapper/
    - $GRADLE_USER_HOME/build-cache/

/cacheフォルダは自動的に保持されますが、わかりやすくするためにキャッシュ構成を保持しています。

6
patrickf