美文网首页
Gradle学习笔记

Gradle学习笔记

作者: 无知者云 | 来源:发表于2019-04-04 09:10 被阅读0次
    • 本笔记比较琐碎,要系统的学习gradle请参考我的gradle学习系列
    • 在Groovy中,方法调用可以不带括号,只要改方法接受至少一个参数(包含closure参数),比如:
    dependencies {
        testCompile 'junit:junit:4.11'
    }
    

    在上例中,dependencies其实是一个函数,后面跟了一个inline的closure参数。

    • 在Groovy中,如果方法没有参数,那么在调用的时候就必须跟上括号。
    • Gradle的语法对于初学者理解起来比较吃力,可以参考这里这里
    • 在Groovy中,在定义closure时并不会执行,只有在实际调用时才会执行closure中的指令:
    def myClosure = { println 'Hello world!' }
    //execute our closure
    myClosure()
    
    • 调用wrapper指定gradle版本:
    gradle wrapper --gradle-version 5.3.1
    
    • 初始化java项目:
    gradle init --type java-application
    
    • 查看项目中的所有properties:
     ./gradlew properties
    
    • Gradle本身存在很多properties值用于控制gradle自己的java进程,通常
    • junit和testng测试总是在单独的JVM中运行。
    • 在Gradle中设置system properties:
      1. 通过gradle -D MyProperty=foo run
      2. 通过在gradle.properties中定义systemProp.propName=propValue
    • Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command.
    • gradle.properties里面定义属于project的properties:
    systemProp.sample = Gradle is gr8 // 系统变量,不属于Project
    sample = Gradle is great //属于Project
    
    • Everything in Gradle sits on top of two basic concepts: projects and tasks.
    • Any method you call in your build script which is not defined in the build script, is delegated to the Project object.
    • Any property you access in your build script, which is not defined in the build script, is delegated to the Project object.
    • All enhanced objects in Gradle’s domain model can hold extra user-defined properties. This includes, but is not limited to, projects, tasks, and source sets. Extra properties can be added, read and set via the owning object’s ext property. Alternatively, an ext block can be used to add multiple properties at once. Extra properties can be accessed from anywhere their owning object can be accessed, giving them a wider scope than local variables. Extra properties on a project are visible from its subprojects.

    相关文章

      网友评论

          本文标题:Gradle学习笔记

          本文链接:https://www.haomeiwen.com/subject/fcitiqtx.html