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.

Gradle Goodness: Changing Name of Default Build File的更多相关文章

  1. Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

    Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have ...

  2. Gradle Goodness: Continue Build Even with Failed Tasks

    If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...

  3. Eclipse项目导入Android Stuio 配置出现 Timeout waiting to lock buildscript class cache for build file 'H:\studioproject\Generic_SN\build.gradle'

     Eclipse项目导入Android Stuio 配置出现 Error:Timeout waiting to lock buildscript class cache for build file  ...

  4. Gradle Goodness: Run a Build Script With a Different Name

    Normally Gradle looks for a build script file with the name build.gradle in the current directory to ...

  5. Gradle Goodness: Add Incremental Build Support to Tasks

    Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unle ...

  6. Gradle Goodness: Copy Files with Filtering

    Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...

  7. Gradle Goodness: Task Output Annotations Create Directory Automatically

    Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...

  8. Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

    Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...

  9. Gradle Goodness: Using and Working with Gradle Version

    To get the current Gradle version we can use the gradleVersion property of the Gradle object. This r ...

随机推荐

  1. 详细解析 HTTP 与 HTTPS 的区别

    详细解析 HTTP 与 HTTPS 的区别 超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览 ...

  2. centos install redis

    1. 下载 [logan@localhost java]$ wget http://download.redis.io/releases/redis-3.2.8.tar.gz2. 解压    [log ...

  3. 什么是APP???APP的开发类型又分哪几种???

    开发者们都知道在高端智能手机系统中有两种应用程序: 一种是基于本地(操作系统)运行的APP —-Native App: 一种是基于高端机的浏览器运行的App —-WebApp因为这些高端智能手机(Ip ...

  4. html标签篇(2)

    上次讲到<a>标签,并没有细说a标签用法. <!DOCTYPE html> <html lang="en"> <head>  < ...

  5. visual studio code断点调试react

    在项目配置文件   .vscode\launch.json 中添加:   "sourceMaps": true,   "skipFiles": [   &quo ...

  6. lua中的weak table

    weakTable = {} weakTable[] = function() print("i am the first element") end weakTable[] = ...

  7. Android学习——Service(一)

    这篇博文来介绍Android另一个十分重要的组件,Service.Service和Activity很类似,区别在于它运行在后台,不可见且没有界面.Service的优先级高于Activity,当系统负载 ...

  8. Angular2 备忘

    ng serve --port 80 --disable-host-check  启动80端口,禁用host检查 要在 component 内绑定全局事件的话,可以使用 @HostListener, ...

  9. Oracle实例初始化参数详解

    BACKGROUND_DUMP_DEST 显示和设置Oracle数据库相关日志的存放地,Oracle11g后不再可配置,但其值仍可显示相关日志的存放地,对应配置参数为diagnostic_dest U ...

  10. C++ 源代码到可执行代码的详细过程

    编译,编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序. 源代码-- ...