Android Gradle

Gradleware released Gradle 2.3 this week, so I decided to write my overdue post about Gradle and the new Android buildsystem for Android Studio.

Google announced the new Gradle-based build system on Mai 15, 2013 at Google I/O in San francisco.

 

 

Gradle is first of all an open-source build system
general purpose platform agnostic with extensions for java, c++, scala, android, et cetera

what are the benefiz of gradle to make it worth, switching from maven or ant

  • performance
  • maintainability
  • usability
  • extendability
  • standardazitaion

 

A Famous quote has nothing to do with software development but you can apply it

We make the impossible possible, the possible easy, and the easy elegant.

Gradleware, the company behind Gradle, want to apply those requirements in gradle

 

Basics of Groovy and Gradle

Groovy runs inside the Java Virtual Machine and makes use of Java's libraries.

{"Groovy is Java with an additional jar file as dependency, Groovy in Action - Dierk Konig"}

 

Groovy reuses Java semantics and API, but removes a lot of syntax noise eg. semicolons

So every Groovy type is a subtype of java.lang.Object and every object is an instance of a type in the normal way.

 

Syntax alignment

import java.util.*;         // Java
Date today = new Date();    // Java

today = new Date()          // Groovy

require 'date'              # Ruby
today = Date.new            # Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
apply plugin: "java"
description = "This is my description"

repositories {
  mavenCentral()
}

dependencies {
  compile "org.springframework:spring-core:4.0.5.RELEASE"
}

test {
  jvmArgs "-Xmx1024m"
}

Gradle build scripts

  • written in a Groovy-based DSL
  • Tasks and plugins can be written in Groovy
  • named build.gradle by default
  • doesn’t run in groovy runtime

Tasks

Running 'gradle tasks' gives you a list of the main tasks of the selected project

add '-b' or '--build-file' for customized script name eg. 'gradle -b test.gradle tasks'

1
2
3
4
5
6
7
8
9
task sampleTask {
    doFirst {
        println "doFirst"
    }

    doLast {
        println "doLast"
    }
}

All Tasks implement the org.gradle.api.Task interface.

You can find all methods on the official documentation:

http://gradle.org/docs/current/dsl/org.gradle.api.Task.html#N16B7D +