Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Creating Build Automation with Gradle

Build Automation is an important part of continuous integration, and a necessary component of many automated pipelines. Gradle is a powerful build automation tool. This learning activity will guide you through the process of implementing a basic gradle build. After completing this activity, you should have a working knowledge of the basics of build automation in gradle.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 0m
Published
Clock icon Jul 08, 2018

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Your personal fork of the git repository is cloned to the cloud server

    You need to clone your personal fork of the sample git repository to the cloud server. Make sure you perform the clone from your home directory.

    You can do so like this:

     cd ~/
     git clone [email protected]:<your_username>/cicd-pipeline-train-schedule-gradle.git
    
  2. Challenge

    You initialized the project as a gradle project

    Once you have cloned the git repo to your home directory, cd into the repo directory and then initialize the gradle build.

     cd ~/cicd-pipeline-train-schedule-gradle
     ./gradlew init
    
  3. Challenge

    Your gradle build generates a zip archive of the application in `dist/trainSchedule.zip`

    The gradle build should generate an archive of the application in dist/trainSchedule.zip.

    You can do this by adding a task to create this archive to build.gradle and ensuring the build task depends on it.

    task zip(type: Zip) {
        from ('.') {
    	    include "*"
    	    include "bin/**"
    	    include "data/**"
    	    include "node_modules/**"
    	    include "public/**"
    	    include "routes/**"
    	    include "views/**"
        }
        destinationDir(file("dist"))
        baseName "trainSchedule"
    }
    
    build.dependsOn zip
    zip.dependsOn npm_build
    

    The full build.gradle file should look like this :

    plugins {
      id("com.github.node-gradle.node") version "2.2.4"
    }
    
    node {
      version    = '9.11.2'
      download   = true
    }
    
    task build
    
    task zip(type: Zip) {
      from ('.') {
        include "*"
        include "bin/**"
        include "data/**"
        include "node_modules/**"
        include "public/**"
        include "routes/**"
        include "views/**"
      }
      destinationDir(file("dist"))
      baseName "trainSchedule"
    }
    
    build.dependsOn zip
    zip.dependsOn npm_build
    build.dependsOn npm_build
    npm_build.dependsOn npmInstall
    npm_build.dependsOn npm_test
    npm_test.dependsOn npmInstall
    

    Then, execute the gradle build to generate the archive:

    ./gradlew build
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans