This article covers shortly how to specify the build file in Gradle. This is useful when we want to have different Gradle build files for our projects, or when we want to build projects in different folders.

1. Default settings

By default, the gradle command looks for a file called build.gradle, which is a build configuration script, in the current directory. So, if it doesn’t find the file here, it will report the build failure.

If the file is presented in the current directory, we will be able to execute the gradle command successfully.

2. Specify The Build File in Gradle

Let’s say we have a project with different build files: build.gradle, build-devops.gradle. By default, Gradle will take the default file in the current directory and run; however, if we want to specify another one, the build-devops.gradle to be built with Gradle, we can add -b option with the specify build file name after the gradle command. For example:

To execute a specific task in that build file, we simply need to append the task after the above command. For example, to list all tasks of the build file.

To execute the helloGradle task which was defined in the build file.

We can leverage this feature to build other projects in different folder, for example:

3. Summary

We have learned about how to specify the build file in Gradle. We can leverage this feature of Gradle to have different build files for a project or build other projects from different folders. This will be convenient for us in organizing build structure for our projects.

Here are other related articles about Gradle, you can refer to them if you’re interested in:

Install Gradle on Ubuntu 16.04 LTS (Xenial Xerus)

Install Gradle on Windows

Where is Gradle Cache Location

Gradle Proxy Settings

Gradle Tutorials

Convert Maven POM File to Gradle Build File

Refresh or Redownload Dependencies in Gradle



0 0 vote
Article Rating