zoukankan      html  css  js  c++  java
  • Gradle Goodness: Changing Name of Default Build File

    Gradle uses the name build.gradle as the default name for a build file. If we write our build code in a file build.gradle then we don't have to specify the build filename when we run tasks. We can create build files with a different name other than build.gradle. For example we can define our build logic in a file sample.gradle. To run the tasks from this build file we can use the command line option -b or --build-file followed by the file name. But we can also change the project settings and set a new default build file name for our project. With the changed project settings we do not have to use the command line options -b or --build-file.

    Suppose we have the following build file with the name sample.gradle:

    0.// File: sample.gradle
    1.task sample(description: 'Sample task') << {
    2.println 'Sample task'
    3.}
    4. 
    5.defaultTasks 'sample'

    To run the sample task from the command line we can use the command line options -b or --build-file:

    $ gradle -b sample.gradle
    :sample
    Sample task
     
    BUILD SUCCESSFUL
     
    Total time: 3.168 secs
    $ gradle --build-file sample.gradle
    :sample
    Sample task
     
    BUILD SUCCESSFUL
     
    Total time: 2.148 secs
    $

    To change the default build file name for our project we create a file settings.gradle in our project. Inside the settings.gradle file we can change the property buildFileName for rootProject:

    0.// File: settings.gradle
    1.// Change default build file name for this project.
    2.rootProject.buildFileName = 'sample.gradle'

    Now we execute the tasks from sample.gradle without the options -b or --build-file:

    $ gradle
    :sample
    Sample task
     
    BUILD SUCCESSFUL
     
    Total time: 3.312 secs
    $

    Code written with Gradle 2.1.

  • 相关阅读:
    【IDEA】创建Maven工程
    【Java】Input,Output,Stream I/O流 03 系统标准流 & 打印流
    【Java】Reflection 反射机制 03调用
    【Java】JDBC Part2 工具类封装实现
    【郝斌C ST】 指针入门
    【Java】Input,Output,Stream I/O流 02 文件流 & 缓冲流
    margin和padding的区别
    JAVA反射机制
    HTTP错误代码详细介绍
    关于Java继承问题
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4188038.html
Copyright © 2011-2022 走看看