Using Gradle for CI


Hey! So we’re having this group project in Software Development where I’ve gotten the job as a tester. Thus, I have to put up an environment in GitLab which automatically builds the code and run the tests people have written in jUnit. Problem is, I have no experience with GitLab or build automation systems (neither do any of the others), so all of this is quite foreign to me.

I know it is common to use Maven, but I figured that if I’m first about to learn how to use such tools I might as well learn Gradle, which I’ve heard is better. So I scoured the web and found three different .gitlab-ci.yml examples, where I got one of them to build after some modification but failed the test with error “Task ‘check’ not found in root project ‘hello’”:

image: gradle:alpine

  - build
  - test

  GRADLE_OPTS: "-Dorg.gradle.daemon=false"

  - export GRADLE_USER_HOME=`pwd`/.gradle

  stage: build
    gradle --build-cache build
      - build/libs/*.jar
    expire_in: 1 week

  stage: test
    gradle check

  - echo "End CI"

The other ones failed the builds with errors:
“/bin/bash: line 72: ./gradlew: No such file or directory”
“Task ‘assemble’ not found in root project ‘hello’”

I tried finding a tutorial for how to set up Gradle in GitLab but to no avail. Would someone please be so kind and give me a step-by-step tutorial for how to set up an automatic test routine with Gradle, or maybe know of some resources that could be helpful? That would be very much appreciated! I guess I have to put a build.gradle file somewhere? I will study these things more thoroughly when I have time, but right now I just need to get it up and running before our sprint starts :grinning:

EDIT: Nevermind, I figured it out :slight_smile: