Build Gradle Applications

Using Gradle, you can automate your build processes as defined in its build script. For more information about Gradle, see https://gradle.org/.

In VB Studio, Gradle 5 is available. To use another version of Gradle, use Gradle Wrapper in the Gradle build step. Gradle recommends using Gradle Wrapper as the preferred way to run a Gradle build. To learn more about using Gradle Wrapper, see https://docs.gradle.org/current/userguide/gradle_wrapper.html.

Set Up a VM Build Executor and a Build Executor Template with Gradle

Before you can create a build step that uses Gradle commands, your organization administrator must create a build executor template that includes the Gradle software and add a VM build executor that uses that build executor template. The build executor template can be created from scratch or software can be added to an existing build executor template.

Note:

To find your organization administrator, click Contacts under your user profile. Your administrator, or a list of administrators, will display.

See Create and Manage Build Executor Templates in Administering Visual Builder Studio.

After the organization administrator adds a VM build executor to the build executor template, you can create and configure a job to use that build executor template and add Gradle commands.

Configure a Job to Run Gradle Commands

Here's how you create and configure a job that runs Gradle commands:

  1. Upload the build.gradle file to a project's Git repository.
  2. Open the job’s configuration page.
    If you're creating a job, in Template in the New Job dialog box, select the Gradle build executor template. Jump to step 5.
  3. Click Settings the Gear icon.
  4. In the Software tab, select the Gradle build executor template.
  5. Click Configure Configure .
  6. In the Git tab, add the Git repository where you uploaded the build file.
  7. Click the Steps tab.
  8. From Add Step, select Gradle.
  9. To use the Gradle installation that comes with the build executor, use the default settings and don't select anything. To use the Gradle wrapper, select Use 'gradlew' wrapper:
    • If you selected Use 'gradlew' wrapper, you can deselect the Create 'gradlew' wrapper check box if you don't want to create a new Gradle wrapper when a build runs. If the check box isn't selected, make sure that the gradlew executable is in the $WORKSPACE directory. If the gradlew executable is in the root build script directory, select the In root build script directory check box.

    • To use a different Gradle version, select Use Gradle version and specify the version in the Gradle version field. The Gradle version is optional.

      Tip:

      To change the Gradle version when a build runs, add a build parameter, perhaps GRADLE_VERSION, and use it here. When a build runs, you can change the default version of Gradle and specify another version.
    • To specify a different distribution mirror, select Use Gradle distribution URL and enter the address in the Gradle distribution URL field. You may want to do this if, for example, you experience intermittent download timeouts. Your company may offer regional mirrors that you can use as an alternative.

  10. In Tasks, enter Gradle tasks.
  11. In Build File, enter the name and path of the Gradle build.gradle file. This path must be relative to the root build script directory, if specified, else relative to the $WORKSPACE directory.
  12. In Root build script directory, enter the directory path that contains the top-level build.gradle file and serves as the project root. The path must be relative to the $WORKSPACE directory.
    If left empty, the path defaults to build.gradle in the root directory.
  13. In Switches, enter Gradle switches.
  14. If you’re using a build executor that is shared by other jobs or users, select the Force GRADLE_USER_HOME to use workspace check box to set GRADLE_USER_HOME to the workspace.
    By default, GRADLE_USER_HOME is set to $HOME/.gradle, so with this option you can avoid encountering unwanted changes in the default shared directory.
  15. Click Save.