5.3.1. Structure of build.gradle

This section describes the structure and main elements of the build.gradle script.


The buildscript section of the script defines the following:

  • A version of the platform.

  • A set of repositories for loading project dependencies. When you create a new project in CUBA Studio, it contains the link to the repository which is selected in the Studio server window. By default it is the public repository:


    If your project uses Premium Add-ons, Studio adds one more repository:


    Both repositories require a user name and a password. While the public repository uses common credentials which are specified right in the build script (cuba / cuba123), the Premium Add-ons repository credentials are provided by per-developer subscription. The first part of your license key before dash is the repository user name, the part after dash is the password. For example, if your key is 111111222222-abcdefabcdef, then the user name is 111111222222 and the password is abcdefabcdef.

    Studio passes to Gradle credentials for repositories when executes the build script. If you want to build the project outside Studio, you can pass premiumRepoUser and premiumRepoPass in the command line arguments with -P prefix:

    gradle assemble -PpremiumRepoUser=111111222222 -PpremiumRepoPass=abcdefabcdef
  • Dependencies used by the build system. The dependecies include the CUBA Gradle plugin and a set of application components used by the project. Components are specified by their global module artifact. In the following example, two components are used: com.haulmont.cuba (cuba component of the platform) and com.company.base (a custom component):

    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
        classpath "com.haulmont.cuba:cuba-global:$cubaVersion"
        classpath "com.company.base:base-global:0.1-SNAPSHOT"

Below the buildscript section, a few variables are defined. They are used in the script later.


The CUBA-specific build logic is encapsulated in the cuba Gradle plugin. It is included in the root of the script and in the configure section of all modules by the following statement:

apply(plugin: 'cuba')

The settings of the cuba plugin are defined in cuba section:

cuba {
    artifact {
        group = 'com.company.sales'
        version = '0.1'
        isSnapshot = true
    tomcat {
        dir = "$project.rootDir/build/tomcat"
    ide {
        copyright = '...'
        classComment = '...'
        vcs = 'Git'

Let us consider the available options:

  • artifact - this section defines the group and version of the project artifacts being built. Artifact names are based on module names specified in settings.gradle.

    • group - artifact group.

    • version - artifact version.

    • isSnapshot - if true, artifact names will have the SNAPSHOT suffix.

  • tomcat - this section defines the settings of the Tomcat server which is used for fast deployment.

    • dir - location of the Tomcat installation directory.

    • port - listening port; 8080 by default.

    • debugPort - Java debug listening port; 8787 by default.

    • shutdownPort - port listening to the SHUTDOWN command; 8005 by default.

    • ajpPort - AJP connector port; 8009 by default.

  • ide - this section contains instructions for Studio and IDE.

    • vcs - a version control system for the project. Only Git and svn are currently supported.

    • copyright - copyright text to be inserted into beginning of each source file.

    • classComment - comment text to be placed above class declarations in Java source files.

  • uploadRepository - this section defines the settings of the repository where assembled project artifacts will be uploaded to upon completion of the uploadArchives task.

    • url - the repository URL. If not specified, Haulmont’s repository is used.

    • user - the repository user.

    • password - the repository password.

      You can pass the upload repository parameters from the command line with the following arguments:

      gradlew uploadArchives -PuploadUrl=http://myrepo.com/content/repositories/snapshots -PuploadUser=me -PuploadPassword=mypassword

The configure sections contain configuration of modules. The most important part of the configuration is the declaration of dependencies. For example:

configure(coreModule) {

    dependencies {
        // standard dependencies using variables defined in the script above
        // add a custom repository-based dependency
        // add a custom file-based dependency
        // add all JAR files in the directory to dependencies
        compile(fileTree(dir: 'libs', include: ['*.jar']))

Non-standard module dependencies can be specified in Studio on the Project properties > Advanced tab. See Studio context help for details.