[Development tool] gradle User Manual: Why should I use gradle?

Source: Internet
Author: User
Tags maven central

Why use gradle?

Gradle is a relatively advanced building system and a good building tool that allows you to customize building logic through plug-ins

The following are the main reasons why Android studio chooses gradle:

  • Use domain specific language to describe and process the building logic. (DSL)
  • Based on groovy. DSL can mix various declarative elements and use code to manipulate these DSL elements for logical customization.
  • Support existing Maven Or Ivy warehouse infrastructure
  • It is very flexible. The use of best practices is not mandatory for you to follow its principles.
  • Other plug-ins can expose their DSL and APIs for use in gradle build files.
  • It is a good API Tool to allow ide integration.

Preparations

  • Gradle 1.6 or 1.7
  • SDK with build tools 17.0.0 (released 5/16/2013)

Basic Project

Under the root directory of the gradle project, there is a file named build. gradle, which describes the overall construction basis of this project.

Build File 

The most basic Java program, its build. gradle file is one sentence:

[Plain]View plaincopy
  1. Apply Plugin: 'java'

For the most basic Android project, its build. gradle is as follows:

 

[Plain]View plaincopy
  1. Buildscript {
  2. Repositories {
  3. Mavencentral ()
  4. }
  5. Dependencies {
  6. Classpath 'com. Android. Tools. Build: gradle: 0.5.6'
  7. }
  8. }
  9. Apply Plugin: 'android'
  10. Android {
  11. Compilesdkversion 17
  12. }

Let's analyze the content of the above three parts step by step.

  • Buildscript {...} is configured with the driver build code, which is declared to be in the maven central repository, taking a classpath dependency, that is, Android plugin for gradle v0.5.6
  • Apply plugin indicates that the plugin used is Android, just as in the previous Java program, the plugin used is Java.
  • All Android build parameters are configured in Android {...}, which is the entry point of Android DSL.

By default, only the target compiling environment is necessary, that is, the attribute compilesdkversion. This is similar to the target attribute in project. properties.

It is worth noting that if you write Apply Plugin: Java rather than apply Plugin: Android in the android project, the build will fail.

[Development tool] gradle User Manual: Why should I use gradle?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.