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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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 git@github.com:<your username>/cicd-pipeline-train-schedule-gradle.git
- 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
- 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.moowork.node" version "1.2.0" } node { 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