Gradle学习笔记

Gradle
  • image-20220809100217152
项目构建
  • 每一个gradle项目都会生成一个build.gradle构建文件

  • image-20220809170251897

  • 一个构建文件代表着一个project (gradle中的一个groovy编写的类)实例

    • 包含一些重要的属性字段

      • group , name , version
    • 包含一些重要的方法

      • apply

        • apply plugin: "java"
          apply plugin: "web"
          
      • dependencies

        • dependencies {
          	api(project(":spring-core"))
          	optional("jakarta.inject:jakarta.inject-api")
          	optional("org.yaml:snakeyaml")
          	optional("org.apache.groovy:groovy-xml")
          	optional("org.jetbrains.kotlin:kotlin-reflect")
          	optional("org.jetbrains.kotlin:kotlin-stdlib")
          	testImplementation(testFixtures(project(":spring-core")))
          	testImplementation(project(":spring-core-test"))
          	testImplementation("jakarta.annotation:jakarta.annotation-api")
          	testFixturesApi("org.junit.jupiter:junit-jupiter-api")
          	testFixturesImplementation("org.assertj:assertj-core")
          }
          
      • repositories

        • repositories {
              mavenCentral()
          }
          
      • task

        • image-20220809170114791
        • 用于定义任务, 任务有任务链, 可以指定, 这个有点像是maven生命周期
        • 任务也可以做成插件(具体有兴趣可以百度)
      • allprojects

        • 一般出现在根模块的build.gradle
      • subprojects

        • 一般出现在根模块的build.gradle

        • allprojects是对所有project的配置,包括Root Project。而subprojects是对所有Child Project的配置

  • 根模块(父模块)和子模块

    • 和maven的概念相同, 只是配置上的差异

    • 相同项目中不同模块之间的快捷引用

      • dependencies {
        	api(project(":spring-core"))
        	testImplementation(testFixtures(project(":spring-core")))
        	testImplementation(project(":spring-core-test"))
        }
        
  • settings.gradle

    • 指定一些通用配置
    • rootProject.name = ‘XXX’ // 指定根项目名称
    • include “XXX” // 指定包含哪些子模块
  • gradle.properties

    • 指定一些通用配置的一些属性

生命周期

  • compile

    编译范围依赖在所有的 classpath 中可用,同时它们也会被打包

    runtime

    runtime 依赖在运行和测试系统的时候需要,但在编译的时候不需要。比如,你可能在编译的时候只需要 JDBC API JAR,而只有在运行的时候才需要 JDBC 驱动实现

    testCompile

    测试期编译需要的附加依赖

    testRuntime

    测试运行期需要

    不同的插件提供了不同的标准配置,你甚至也可以定义属于自己的配置项

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BinBin_Bang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值