Git Product home page Git Product logo

gradletutorial's Introduction

GradleTutorial

A repository for notes and example script(s) for the the basic tutorial on the Gradle website.

Installation

The tutorial actually assumes you've already downloaded and installed Gradle -- so the first step for me was to grab Gradle.

For Unix, MacOS, etc.

Homebrew is your friend. Checkout this article for hints on using Homebrew to install Gradle.

Installing Gradle on MacOS

For Windows

Either Chocolatey, Scoop or just download the latest from the Gradle website.

Tutorial

The files in this repository were all created while following this tutorial on the offical Gradle website:

Creating New Gradle Builds

Steps

Step 1: Create a folder and build file

  1. Create a folder for the tutorial, call it something like /gradle-demo/.

  2. Inside your new folder create a Gradle build file - build.gradle.

Step 2: Checkout the Tasks command

  1. Run the gradle tasks command to see the default tasks available from Gradle.

Step 3: Generate a Gradle Wrapper

  1. Run the gradle wrapper command to automatically generate a Gradle wrapper file.

This is an interesting step because you are making it so that a future user/client of your project won't have to download and setup Gradle - they can simply use the generated Gradle wrapper (gradlew or gradlew.bat on Windows) on their platform of choice -- and Gradle will automagically be downloaded and configured. See the tutorial for more details on what folders and files are generated with this command.

Step 4: Checkout the Properties command

  1. Run the gradlew properties command to see the properties that are avaiable from Gradle.

  2. Add some properties to your build.gradle file and re-run the gradle properties to see that your added properties are used -- in fact the description is used at the top of the output!

Step 5: Create a Grade core task

  1. Create a folder inside your tutorial folder called /src/.

  2. Create a file inside your src folder called something like myfile.txt - add some text to it just for fun -- like "Hello, World!".

  3. Now, the fun part, you are going to create a task inside your build.gradle file that'll make use of the folder and file you just created -- to demonstrate some of the built in capabilities of Gradle (Core).

task copy(type: Copy) {
    from 'src'
    into 'dest'
}
  1. Now, re-run Step 2 to list out all of the Gradle tasks, including your newly created copy task.

  2. Finally, execute your copy task by running ./gradlew copy (or gradlew copy or Windows)

Step 6: Create a Gradle core task using a plugins

  1. At the top of your build.gradle you'll need to add a reference to a plugins
plugins {
    id 'base'
}
  1. Then, below your first task, create a new one that makes use of the plugin your just added.
task zip(type: Zip) {
    from 'src'
}
  1. Now, re-run Step 2 again so you can confirm that you see your new task.

  2. Finally, run your task by running ./gradlew zip and note that in the build/distributions/ folder there is a zip file named after your project folder.

  3. Now, just so you can see some other capabilities of Gradle, you can use one of the built in tasks, called Clean to clean up. ./gradlew clean Note, it'll remove the build folder that you just generate the zip file into.

Step 7: Create a Gradle ad hoc task

  1. This time you're just going to create a simple ad hoc task in the same build.gradle file.
task hello {
    doLast {
        println 'Hello, World!'
    }
}
  1. Now, to wrap up, you can run your newly created task by running ./gradlew hello.

This is a very simple introduction to an interesting concept -- writing custom Gradle tasks.

gradletutorial's People

Contributors

kevinjdonohue avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.