5.3.1. The Structure of build.gradle

The allprojects section defines the group and version of the project artifacts being built. Artifact names are based on module names specified in settings.gradle. If the ext.isSnapshot property is true, artifact names will have the SNAPSHOT suffix. The ext.tomcatDir property sets the location of the Tomcat installation directory. Furthermore, the allprojects section may have the following optional properties:

  • ext.copyright – the copyright notice text that is inserted by IntelliJ IDEA into the source text files.

  • ext.vcs – type of VCS used in the project. If this property is specified, IntelliJ IDEA’s generated project files will have a VCS integration parameter for this VCS. Possible values: svn, git.

  • ext.uploadUrl – URL of the repository where assembled project artifacts will be uploaded to upon completion of the uploadArchives task. Haulmont repository is used by default.

  • ext.uploadUser – name of the repository user that will be used to upload assembled project artifacts. HAULMONT_REPOSITORY_USER environment variable value is used by default.

  • ext.uploadPassword repository user password that will be used to upload assembled project artifacts. HAULMONT_REPOSITORY_PASSWORD environment variable value is used by default.

  • ext.tomcatPort, ext.tomcatShutdownPort and ext.tomcatDebugPort properties affect the setupTomcat task (see below) and can be used to install Tomcat with non-standard ports.

Instead of setting project properties in build.gradle itself, you can do it by passing a command-line argument with the -P prefix, for example:

gradlew uploadArchives -PuploadUser=myuser -PuploadPassword=mypassword

In the buildscript section, the following actions are executed:

  • The base projects version is specified.

  • The set of repositories for loading project dependencies is specified. Values of repoUser and repoPass project properties or standard values explicitly set in the build script are used as credentials to access the repository. Similar to other project properties, you can pass repoUser and repoPass in the command line arguments with -P prefix.

  • Dependency from the cuba-plugin is declared; the plugin contains the project's build specifics and is connected to the module build configuration using the following method:

    apply(plugin: 'cuba')

Then, application modules building parameters are defined in the configure section.

Tasks are executable units in Gradle. They are defined both in the plugins and in the build script itself. Below are CUBA-specific tasks; their parameters can be configured in build.gradle.

  • enhance – the CubaEnhancing-type task that executes bytecode enhancement of persistent entity classes. It is declared in the global module. The path to the persistence.xml project file is specified in the persistenceXml task parameter.

    For example:

    task enhance(type: CubaEnhancing) {
        persistenceXml = "${globalModule.projectDir}/src/persistence.xml"
    }
  • enhanceTransient – the CubaEnhanceTransient-type task that executes bytecode enhancement of non-persistent entity classes. The path to the metadata.xml project file is specified in the metadataXml task parameter.

    For example:

    task enhanceTransient(type: CubaEnhanceTransient) {
        metadataXml = "${globalModule.projectDir}/src/metadata.xml"
    }
  • setupTomcat – the CubaSetupTomcat-type task that performs installation and initialization of the local Tomcat server for subsequent fast deployment of the application. This task is automatically added to the project when you connect the cuba build plugin, so you don’t need to declare it in build.gradle. Tomcat installation directory is specified by the ext.tomcatDir property in the allprojects section. By default, it is the project’s build/tomcat subfolder.

  • deploy – the CubaDeployment-type task that performs fast deployment of a module to Tomcat. It is declared in the core, web and portal modules. Parameters:

    • appName – name of the web application that will be created from the module. In fact, it is the name of a subdirectory inside tomcat/webapps.

    • jarNames – the list of JAR file names (without versions) produced as a result of building a module and intended to be placed into the WEB-INF/lib catalog of the web application. All other module artifacts and dependencies will be copied to tomcat/shared/lib.

    For example:

    task deploy(dependsOn: assemble, type: CubaDeployment) {
        appName = 'app-core'
        jarNames = ['cuba-global', 'cuba-core', 'app-global', 'app-core']
    }
  • buildWar – the CubaWarBuilding-type task that builds a module into a WAR file. It can be declared in the core, web and portal modules, if application deployment to WAR is required. The built WAR files are located in the build/distributions module subdirectories.

    Task parameters:

    • appName – the name of the resulting WAR file.

    • appHome – the path to the application home directory. The home directory contains the logging configuration file, the database scripts directory, and the configuration, temporary and work directories of the application.

      In the appHome parameter, you can specify either an absolute path to the home directory or a system variable, which should be set at server start. For example: appHome = '/work/sales_home' or appHome = '${app.home}'.

    • appProperties – the map of the properties that will be written to the WEB-INF/local.app.properties file in addition to those defined in the task itself. By default, the buildWar task creates this file and defines properties cuba.logDir, cuba.confDir, cuba.tempDir, cuba.dataDir in it, in order to work with the application home directory mentioned above. Additionally, the following parameter is set for the middleware:

      cuba.dataSourceJndiName = jdbc/CubaDS

      and for the web client:

      cuba.connectionUrl = http://localhost:8080/${appName}-core
      cuba.useLocalServiceInvocation = false

    An example of a task in the web module:

    task buildWar(dependsOn: assemble, type: CubaWarBuilding) {
        appName = 'app'
        appHome = '${app.home}'
        appProperties = ['cuba.connectionUrlList': 'http://server/app-core']
    }

  • createWarDistr – the CubaWarDistribution-type task that prepares the distribution that includes application WAR files and their home directory. The task must depend on the tasks of the buildWar module and have the following parameters:

    • appHome – the path to the home directory of the application (see buildWar task description for details).

    • distrDir – target folder for the distribution content. It is an optional parameter; by default, the build/war project subdirectory is used.

    Below is a sample task description:

    task createWarDistr(dependsOn: [coreModule.buildWar, webModule.buildWar], type: CubaWarDistribution) {
        appHome = '${app.home}'
    }
  • createDb – the CubaDbCreation-type task that creates application database by executing the corresponding scripts. It is declared in the core module. Parameters:

    • dbms – the DBMS type; specified as string (hsql, postgres, mssql, or oracle).

    • dbName – the database name.

    • dbUser – the DBMS username.

    • dbPassword – the DBMS user password.

    • host – the DBMS host and port (optional) in the host[:port] format. If not specified, localhost is used.

    • masterUrl – the URL used to connect when creating the database. If not specified, the default value that depends on the DBMS type and the host parameter is used.

    • dropDbSql – the SQL command to delete the database. If not specified, the default value that depends on the DBMS type is used.

    • createDbSql – the SQL command to create a database. If not specified, the default value that depends on the DBMS type is used.

    • driverClasspath – the list of JAR files containing the JDBC driver. The items in the list are separated by ":" on Linux and by ";" on Windows. If not specified, the system uses the dependencies that are part of the current module’s jdbc configuration. Explicit definition of driverClasspath is necessary when using Oracle, because its JDBC driver is not available in the dependencies.

    • oracleSystemPassword – the SYSTEM user password for Oracle.

    Example for PostgreSQL:

    task createDb(dependsOn: assemble, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'postgres'
        dbName = 'sales'
        dbUser = 'cuba'
        dbPassword = 'cuba'
    }

    Example for MS SQL Server:

    task createDb(dependsOn: assemble, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'mssql'
        dbName = 'sales'
        dbUser = 'sa'
        dbPassword = 'saPass1'
    }

    Example for Oracle:

    task createDb(dependsOn: assemble, description: 'Creates database', type: CubaDbCreation) {
        dbms = 'oracle'
        host = '192.168.1.10'
        dbName = 'orcl'
        dbUser = 'sales'
        dbPassword = 'sales'
        oracleSystemPassword = 'manager'
        driverClasspath = "$tomcatDir/lib/ojdbc6.jar"
    }
  • updateDb – the CubaDbUpdate-type task that updates the database by executing the corresponding scripts. It is similar to the createDb task, except that the dropDbSql and createDbSql parameters are omitted.

  • startDb – the CubaHsqlStart-type task that starts the local HSQLDB server. Parameters:

    • dbName – database name, default is cubadb.

    • dbDataDir – database directory, default is the data subfolder of the project.

    • dbPort – server port, default is 9001.

    For example:

    task startDb(type: CubaHsqlStart) {
        dbName = 'sales'
    }

  • stopDb – the CubaHsqlStop-type task that stops the local HSQLDB server. The parameters are similar to startDb.

  • start – the CubaStartTomcat-type task that starts the local Tomcat server installed by the setupTomcat task. This task is automatically added to the project when you add the cuba plugin, so you don’t need to declare it in build.gradle.

  • stop – the CubaStopTomcat type task that stops the local Tomcat server installed by the setupTomcat task. This task is automatically added to the project when you include the cuba plugin, so you don’t need to declare it in build.gradle.

  • restart – the task that stops the local Tomcat server, runs fast deployment, and starts the server once again.

  • debugWidgetSet - the CubaWidgetSetDebug type task that launches GWT Code Server for debugging widgets in the browser.

    Example usage:

    task debugWidgetSet(type: CubaWidgetSetDebug) {
        widgetSetClass = 'com.haulmont.cuba.web.toolkit.ui.WidgetSet'
    }

    Ensure that the web-toolkit module has a dependency on Servlet API library in the runtime configuration:

    configure(webToolkitModule) {
        dependencies {
            runtime(servletApi)
        }
    ...

    See Section 5.7.2, “Debugging Web Widgets” for information on how to debug code in the browser.