gradle build tools

  When using android studio to develop android programs, as is built based on gradle, we only need to run it to compile, package and install, which is very convenient, but what exactly is gradle?   

  

1. java build tool

  First, we need to know what a build tool is. In fact, a build tool is a programmable tool that can help us perform ordered tasks, automate projects, and reduce or even avoid unnecessary manual operations, that is, a build tool is a tool that liberates productivity and improves efficient. In the front-end, webpack is a build tool. It can not only package, but also complete a series of tasks such as testing, hot update, deployment, inspection, optimization, etc., thus realizing the engineering of development and improving efficiency.

  In java, the following build tools are also commonly used:

  • Ant - The core of Ant is written in Java, and xml is used as the build script. It is based on the idea of ​​task chain, defines dependencies between tasks, forms a sequence, and then completes them one by one. However, XML to define the build script will make the script very bloated, because the XML is too large, unless it is a small project, which makes it difficult for us to maintain. Just as the front-end and back-end data transmission used xml, but now json is used, it is because the shortcomings of xml are too obvious.
  • Maven - Maven is commonly used, including now, is widely used by many java engineers. The development team of the Maven build tool is aware of the defects of Ant, adopts a standard project layout and a unified life cycle, adopts the idea of ​​​​conventional configuration, and reduces the writing content required by the build script. Its community is active, and it is easy to find suitable plugins. Is a very powerful dependency management tool. But Maven also uses xml, and using the default structure and life cycle is too restrictive, and it is also troublesome to write plugin extensions.
  • Gradle - It combines the best of the first two, with the power and flexibility of ant, but also the lifecycle management of Maven and ease of use. In addition, Gradle does not use xml but a Groovy-based DSL, so Gradle build scripts are more concise and clearer than Ant and Maven and their code is small, because the DSL is designed to solve specific problems, throughout the software life cycle, from compilation From static checking to testing to packaging and deployment.

  

 

二、Gradle

  It was introduced earlier that Gradle is a more convenient build tool based on ant and maven, and it was mentioned that it is based on groovy, but what is DSL?

  DSL is Domain Specific Language. Its basic idea is "seeking specialization without seeking perfection", that is, DSL is used for building tools, not for numerical calculation, etc. Its purpose is very single, only for A computer language for a particular problem.

  The syntax of Groovy and java is very similar, but it is a dynamic language. Like java, it runs in the java virtual machine, so we can think that Groovy extends the java language. The following is the relationship between java, Groovy and jre:

    In fact, when Groovy Code is actually executed, it has actually become java bytecode, so the JVM does not know that it is running Groovy code at all.

  

 

3. Gradle Workflow

  The following diagram can be used to illustrate the Gradle workflow:

    

  That is, a Gradle job consists of three stages:

  • Initialization phase. For projects created through as, settings.gradle is executed.
  • The next phase of the initialization phase is the Configuration phase. Its goal is to parse the build.gradle in each project.
  • The last phase is the Execution phase.

  Note that after each stage we can have hooks to execute custom functions.

 

Reference article: https://blog.csdn.net/Innost/article/details/48228651

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325269311&siteId=291194637
Recommended