Meet gradle again

  • Overview

    " First understanding of gradle||install||primary use "

  • Popular understanding of gradle

    The tedious work caused by different software release channels, different mobile phone models, and different dependencies can all be solved by Gradle.

    Gradle is a build tool that can help you manage differences, dependencies, compilation, packaging, deployment...You can define the build logic that meets your needs and write it to the build.gradlemiddle for future reuse.

    Grdle is not a programming language, and it cannot help you implement any actual functions in the software.

  • ant

    Ant can automate packaging logic

  • maven

    mavenColleagues who can automate packaging logic can also download jar packages automatically.

    GradleBoth capable work mavenand capable work ant.

    GradleIt is not only a configuration script, but several languages ​​behind it:

    1. Groovy Language
    2. Gradle DSL
    3. Android DSL
  • The basic composition of Gradle

    ProjectAnd Taskare the two basic concepts of Gradle :

    • Project, Refers to our build products (such as jarpackages) or implementation products (deploy the application to the production environment)
    • Task, Refers to the smallest unit of work that cannot be separated and performs construction work

    Each construction is made up of one or more projects, and each construction is made up of projectone or more task.

  • The composition of the Gradle build system

    Any build system is composed of multiple build files:

    • Ant consists build.xmlof
    • Maven consists pom.xmlof
    • Make consists makefileof
    • Gradle consists build.gradle settings.gradle gradle.propertiesof
      1. build.gradle The build script defines a module and compiling tasks, which are generally placed in the project's module, or can be placed in the root directory of the project as a global setting for the compilation structure. It is a must
      2. setting.gradleIt's required. In order to define a multi-project build, you need to create a settings file and place it in the root directory of the source code to specify which projects to include.
      3. gradle.propertiesUsed to configure build properties, not required
  • Gradle plugin

    Gradle 's design philosophy is that all useful features are provided by Gradle plugins.

    groovyPlug-in, which extends the Javaplug-in and adds the Groovydependency of compilation ;

    warThe plug-in is actually javaexpanded on the basis of the plug-in to build WARfiles;

    JettyThe plug-in is actually Warexpanded on the basis of the plug-in, and the word order user publishes the web application to an intervening Jettycontainer.

  • Gradle running process

    You can run a command by gradle Gradle build , gradlecommand looks for a call in the current directory build.gradlefile, this build.gradlefile is called a build script.

    # 创建文件build.gradle
    task hello {
          
          
    	doLast {
          
          
    		println 'Hello World!'
    	}
    }
    # 命令行运行
    > gradle -q hello # -q是quiet模式,不产生gradle的日志信息
    Hello World!
    

    Here, the build script build.gradledefines an independent task, called hello, then added a actionrun when the command line gradle hello, Gradle execution is called hellothe task, which is carried out taskof action, this actionis a contains some Groovy code 闭包closure.

    > gradle buildHere buildis a plugin javabuilt-in task task, gradle clean, gradle assemble, gradle check, gradle propertiesibid.

    > gradle compile test # 实现一次调用多个`task`,`compile`, `test`会被依次调用。
    > gradle dist -x test # 命令行选项-x用来排除某些任务
    > gradle --continue # --continue选项,某任务调用失败后继续执行后续任务,以期发现跟多错误
    > -b # -b参数用于选择其他目录的构建文件,且settings.gradle将不会生效
    > -p # -b是指定脚本,-p是指定脚本所在的目录
    > gradle projects # 列出子项目名称列表
    > gradle tasks # 列出项目中所有任务
    > gradle tasks --all # --all 列出项目中所有任务以及任务之间的依赖关系
    > gradle help --task someTask # 显示指定任务的详细信息
    > gradle dependencies # 列出项目的依赖列表
    > gradle dependencyInsight # 查看指定的依赖
    > gradle properties # 获取项目所有属性列表
    > gradle --profile # 收集构建期间的信息并保存到build/reports/profile目录下,以构建时间命名
    > gradle -i # INFO log
    > gradle -d # DEBUG log
    
  • Gradle repository

    Gradle will repositoryfind various dependent files in one .

    repositoryIs a collection of files, by group, name, versionfinishing classification.

    Gradle can parse out several different warehouse forms, such as mavenand ivy, and can understand various ways to enter the warehouse, such as using the local file system or HTTP.

  • Project properties||variables

    projectObject provides a number of standard attributes: project, name, path, description, projectDir, build, group, version, ant.

    There are two types of variables in the Gradle build script :

    • Local variables ( local),def
    • Expansion variables ( extra).
  • Gradle Build Language References

    Gradle scripts are configuration scripts.

    As the script executes, it configures an object of a particular type.

  • References

  1. Zhihu: How to understand Gradle in a popular way?
  2. The basic use of Gradle (1) ( 2 ) ( 3 )
  3. Gradle User Manual
  4. Gradle Started
  5. Building Java Application Sample

Guess you like

Origin blog.csdn.net/The_Time_Runner/article/details/113000987
Recommended