Skip to main content

The Great Gradle Cheat Sheet

This article intend to work as a gradle in nutshell. I will try to keep it as concise as possible while trying to touch as many frequently used gradle operations as possible.

Task Chain

task compile {
    doLast {
        println 'compiling source'
    }
}

task compileTest(dependsOn: compile) {
    doLast {
        println 'compiling unit tests'
    }
}

# gradle compileTest
Above command will execute "compile" task first and then compileTest.

Excluding Tasks with -x

#gradle compileTest -x compile

Abbreviating task names by camel initials

#gradle compileTest
#gradle ct  


Running subproject

#gradle -p subdir compileTest

Listing all tasks

#gradle -q tasks

List project dependencies

#gradle -q dependencies

Listing build script dependencies

gradle buildEnvironment

List project properties

gradle -q properties

Profiling build operation
gradle build --profile

Above command generates nice report about time taken in each steps as shown below.




Pre-check the order of tasks

Use -m flag to mock run (dry run) the task. It will list out all the tasks in the order of execution.
gradle -m build

Using gradlew instead of gradle

If you feel installing gradle and maintaing same version across all users is a burden, you can use gradle wrapper. Gradle wrapper is the gradle script which can be kept at the root of the project and checkin to your code repository so that all users have it. Once it is done, all gradle commands can be run as ./gradlew instead of gradle. Following gradle task installs the gradle wrapper.

gradle wrapper --gradle-version 2.0

Dependency resolution

Dependencies can be declared by following dependency configuration
dependencies {
    compile 'org.hibernate:hibernate-core:3.6.7.Final'
}

The syntax is compile 'group:name:version'

Repository declaration

We need to tell gradle the source from where dependencies can be downloaded. It is done via following configuration:
repositories {
    mavenCentral(),
    jcenter()
}

Variables for gradle script

Variables declared in the gradle.properties file gets available to be used in gradle file. If variable has prefix "sytemProps", those get available as system variable. System variable are accessed as System.properties['variable_name']

User-specific variables can be set in gradle.properties at the location <User-Home>/.gradle/gradle.properties  User-specific variables gets precedence over project specific gradle.properties
to be continued...

Comments

  1. Great Article
    Cloud Computing Projects


    Networking Projects

    Final Year Projects for CSE


    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete

Post a Comment

Popular posts from this blog

Auto Scaling DynamoDB

Those of you who have worked with the DynamoDB long enough, will be aware of the tricky scaling policies of DynamoDB. It allows user to explicitly set requests per second (units per second, but for simplicity we will just say request per second). User can do so for read as well as write operations. Anytime user can increase or decrease the provision capacity from DynamoDB web console and it will reflect immediately. Sounds all good....... Or not? What if you set provisioned capacity to 50 req per second but load on the server crosses 100 req per second? Requests gets throttled!! Mostly times out. What's worse? This can cause requests getting queued up in your web server. Which can potentially bring your entire server down. What if you set provisioned capacity to 1000 req per second but load on the server is only 100 req per second through out the day? You lose your hard earned money for remaining 900 req per second. What if you set it to 1000 req per sec and then realis

StackDriver Integration with AWS Elastic Beanstalk - Part 1

Stack Driver Setup Step 1: Create stackdriver project Navigate to https://stackdriver.com  After logging in you will be redirected to project creation page. To manage multiple environments of your application its advisable that you create just two projects. One for production env and other one for non-prod. Even though you might have multiple non-production environments, but having one stackdriver project per application-env is overkill. So, lets start with production project. For this tutorial, I'll create CodeHooDoo-Prod project. Once the project is created, StackDriver will ask you to link your AWS account resources to it for monitoring.  But as AWS CloudWatch has good monitoring and alerting support you can skip this one. Keep clicking continue until you get to monitoring console. Click on the logging. This is where you will get all the logs from your application server. Step 2: Download authentication key Navigate backt to https://stackdriver.com .