Gradle goodness:changing Name of the Default Build File

Source: Internet
Author: User

Gradle uses the name as the build.gradle default name for a build file. If We write our build code in a file then we do not have the build.gradle "to specify" the build filename when we run the 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 to our project. With the changed project settings we don't have the command line options -b or --build-file .

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

View Sourceprint? 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 of file name for our project we create a file with our settings.gradle project. Inside The settings.gradle file we can change the property buildFileName for rootProject :

View Sourceprint? 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 the Default Build File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.