-
-
Save daicham/5ac8461b8b49385244aa0977638c3420 to your computer and use it in GitHub Desktop.
image: java:8-jdk | |
stages: | |
- build | |
- test | |
- deploy | |
before_script: | |
# - echo `pwd` # debug | |
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug | |
- export GRADLE_USER_HOME=`pwd`/.gradle | |
cache: | |
paths: | |
- .gradle/wrapper | |
- .gradle/caches | |
build: | |
stage: build | |
script: | |
- ./gradlew assemble | |
artifacts: | |
paths: | |
- build/libs/*.jar | |
expire_in: 1 week | |
only: | |
- master | |
test: | |
stage: test | |
script: | |
- ./gradlew check | |
deploy: | |
stage: deploy | |
script: | |
- ./deploy | |
after_script: | |
- echo "End CI" |
Excellent.
very nice
@VinnieM just don't use ant which is deprecated
I'm not sure whether the script actually works. The cache references files not in $HOME, but in workspace path instead, and in my project there is nothing like .gradle/wrapper
nor .gradle/caches
.
EDIT: ah, missed export GRADLE_USER_HOME=pwd/.gradle
- clever. In that case, maybe lock files needs to be deleted? I have seen this in Travis settings:
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Using reduced version:
image: java:8-jdk
before_script:
- echo `pwd`
- export GRADLE_USER_HOME=`pwd`/.gradle
- rm -f .gradle/caches/modules-2/modules-2.lock
- rm -fr .gradle/caches/*/plugin-resolution/
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
script:
- ./gradlew build
Yet, every time the build is run, gradle re-downloads every dependency and also the whole gradle distribution. Does this mean that the gitlab cache is not working properly/misconfigured somehow? Edit: maybe the problem is in the cache itself: https://forum.gitlab.com/t/cache-not-working/5694
My workaround to cache issue was to cache this:
before_script:
- if [ ! -d /cache$ANDROID_HOME ]; then mv $ANDROID_HOME /cache$ANDROID_HOME; fi
- export ANDROID_HOME=/cache$ANDROID_HOME
- cd LTCfastpay
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x ./gradlew
stages:
- build
- test
- deploy
build:
stage: build
script:
- ./gradlew -g /cache assembleRelease
artifacts:
paths:
- /app/build/outputs/apk
tags:
- android
In this way, ANDROID_HOME and /gradle are cached. This reduce my build time by half.
As far as I know, check
depends on other build tasks, that are performed by assembleRelease
. I'd guess in this example those tasks are run twice. I set everything in the build
folder as an artifact (expiring in 1 day), so those are restored in the test
job, and Gradle will find the redundant tasks up to date, so they are not run. But I'm not 100% percent satisfied, since for a 4MB APK final artifact, this means ~150MB of artifacts to be uploaded (though for 1 day only, but still). Does anyone have a better solution for that?
Excellent script. Runs build and test on Gradle perfectly.
How can we use secret variables as Gradle command line argument? For an example pass user credentials to publish task, Does anyone know a solution? You may answer on this SO, Thanks for the script.
variables:
GRADLE_USER_HOME: '.gradle-cache'
Works fine for me
Very useful, thanks!
@nerzhul Don't spread false information. Ant isn't "deprecated", they just had a new release last March. That said, I do use Gradle for new projects. But this trend is no reason to wage FUD wars against other tech.
Thanks for this, new to CI and this has got me up and running :-)
Yep, thanks a lot!
can anyone provide where will be the default cache will be store and which artifacts we need to add for catching up results
If I want to use Ant instead of Gradle, how would I do that?