The process of building and deploying LabKey Server from source is covered in this topic.

Build Directories

These are the various directories involved in the build process, listed in the order in which they are used in the build process:

  • Source directory - Where the source code lives. This is where developers do their work. The build process uses this as input only.
  • Build directory - Where all the building happens. This is the top-level output directory for the build. It is created if it does not exist when doing any of the build steps.
  • Module build directory - Where the building happens for a module. This is the output directory for a module's build steps. It is created if it does not exist when doing a build.
  • Staging directory - A gathering point for items that are to be deployed. This is just a way station for modules and other jars. The artifacts are collected here so they can be copied all at once into the deploy directory in order to prevent Tomcat from reloading the appliation multiple times when multiple modules are being updated.
  • Deploy directory - The directory where the application is deployed and recognized by Tomcat.
The table below shows the commands used to create, modify and delete the various directories. Since various commands depend on others, there are generally several commands that will affect a given directory. We list here only the commands that would be most commonly used or useful.
Directory TypePath
(relative to <LABKEY_HOME>)
Added to by...Removed from by...Deleted by...
BuildbuildAny build stepAny cleaning stepcleanBuild
Module buildbuild/modules/<module>moduleN/A:server:modules:<module>:clean
One of the key things to note here is the cleanBuild command removes the entire build directory, requiring all of the build steps to be run again. This is generally not what you want or need to do since Gradle's up-to-date checks should be able to determine when things need to be rebuilt. (If that does not seem to be the case, please file a bug.) The one exception to this rule is when we change the LabKey version number after a release. Then you need to do a cleanBuild to get rid of the artifacts with the previous release version in their names.

Application Build Steps

Source code is built into jar files (and other types of files) in a module's build directory. The result is a .module file, which contains potentially several jar files as well as other resources used by the module. This .module file is copied from the module's build directory into the staging directory and from there into the deploy directory. This is all usually accomplished with the './gradlew deployApp' command. The 'deployApp' task also configures and copies the labkey.xml tomcat context file. This file points to the deploy directory as a context path for Tomcat. Changes in that directory will therefore be noticed by Tomcat and cause it to reload the application.

Module Build Steps

A single module is deployed using the `./gradlew deployModule' command. This command will create a .module file in the module's build directory, then copy it first into the staging modules directory and then into the deploy modules directory.

Build Targets

A few important targets:

Gradle TargetoooooooooooooooooooooooooooooooooDescription
gradlew tasksLists all of the available tasks in the current project.
gradlew pickPg
gradlew pickMSSQL
Specify the database server to use. The first time you build LabKey, you need to invoke one of these targets to configure your database settings. If you are running against PostgreSQL, invoke the pickPg target. If you are running against SQL Server, invoke the pickMSSQL target. These targets copy the settings specified in the or file, which you previously modified, to the LabKey configuration file, labkey.xml.
gradlew deployAppBuild the LabKey Server source for development purposes. This is a development-only build that skips many important steps needed for production environments, including GWT compilation for popular browsers, gzipping of scripts, production of Java & JavaScript API documentation, and copying of important resources to the deployment location. Builds produced by this target will not run in production mode.
gradlew :server:modules:wiki:deployModuleFor convenience, every module can be deployed separately. If your changes are restricted to a single module then building just that module is a faster option than a full build. Example, to build the wiki module: 'gradlew :server:modules:wiki:deployModule'.
gradlew deployApp -PdeployMode=prodBuild the LabKey Server source for deployment to a production server. This build takes longer than 'gradlew deployApp' but results in artifacts that are suitable and optimized for production environments.
gradlew cleanBuildDelete all artifacts from previous builds.
gradlew cleanBuild deployAppDelete all artifacts from previous builds and build the LabKey Server from source. This sequence of build targets is sometimes required after certain updates but should generally be avoided as it will cause Gradle to start all over again and not take advantage of previous build work.
gradlew startTomcat
gradlew stopTomcat
Starts/stops the server in dev mode.
gradlew projectsLists the current modules included in the build.
gradlew :server:test:uiTest -Psuite=DRTRun the basic automated test suite.

Gradle targets can also be invoked from within IntelliJ via the "Gradle projects" panel, but this has not been widely tested.

Parallel Build Feature

To speed up the build, consider using the parallel build feature in Gradle.

Use the --parallel flag on the command line:

./gradlew --parallel deployApp

Or set the gradle property org.gradle.parallel to true. Add this line:


either in your top-level file (that is, the one in your <USER_DIR>/.gradle/ file, where you originally set up your artifactory password and such) or in the narrower-scoped <LABKEY_ROOT>/ file. Note that you can also add this property to the command line:


If Gradle warns that "JVM heap space is exhausted", add more memory as described in the topic Gradle Tips and Tricks.

Related Topics


Was this content helpful?

Log in or register an account to provide feedback

expand all collapse all