Below are some additional tips on using Gradle to your advantage and to help learn the Gradle command line.

Flags and Options

Use gradlew -h to see the various options available for running gradle commands.

By default, gradle outputs information related to the progress in building and which tasks it considers as up to date or skipped. If you don’t want to see this, or any other output about progress of the build, you’ll want to add the -q flag:

gradlew -q projects

Set up an alias if you’re a command-line kind of person who can’t abide output to the screen.

Offline Mode

If working offline, you will want to use the --offline option to prevent it from contacting the artifact server (You won’t have success if you do this for your first build.)

Or you can toggle offline mode in IntelliJ, as shown in the following screen shot:

Efficient Builds

If doing development in a single module, there is a command available to you that can be sort of a one-stop shopping experience:

/path/to/gradlew deployModule

This will build the jar files, and the .module file and then copy it to the build/deploy/modules directory, which will cause Tomcat to refresh.

Gradle Paths

Build tasks are available at a fairly granular level, which allows you to use just the tasks you need for your particular development process. The targeting is done by providing the Gradle path (Gradle paths use colons as separators instead of slashes in either direction) to the project as part of the target name. For example, to deploy just the wiki module, you would do the following from the root of the LabKey enlistment:

./gradlew :server:modules:wiki:deployModule

Note that Gradle requires only unique prefixes in the path elements, so you could achieve the same results with less typing as follows:

./gradlew :se:m:w:depl

And when you mistype a target name it will suggest possible targets nearby. For example, if you switch back to ant task mode momentarily and type

gradlew pick_pg

Gradle responds with:

* What went wrong:

Task 'pick_pg' not found in project ':server'. Some candidates are: 'pickPg'.

Gradle's Helpful Tasks

Gradle provides many helpful tasks to advertise the capabilities and settings within the build system. Start with this and see where it leads you

gradlew tasks

Other very useful tasks for troubleshooting are

  • projects - lists the set of projects included in the build
  • dependencies - lists all dependencies, including transitive dependencies, for all the configurations for your build

Paths and Aliases

Placing the gradlew script in your path is not ideal in an environment where different directories/branches may use different versions of gradle (as you will invariably do if you develop on trunk and release branches). Instead, you can:

  • Always run the gradlew command from the root of the enlistment using ./gradlew
  • On Linux/Mac, use the direnv tool.
You may also want to create aliases for your favorite commands in Gradle. If you miss having the timestamp output at the end of your command, check out the tips in this issue.

Performance

Gradle will never be as performant of Ant. It does more work, so it takes more time. But there are various things you can do to improve performance:

  • Use targeted build steps to do just what you know needs to be done.
  • Use the -a option on the command line to not rebuild project dependencies (though you should not be surprised if sometimes your changes do require a rebuild of dependencies that you're not aware of and be prepared to remove that -a option).
  • You can add more memory to the JVM by setting the org.gradle.jvmargs property to something like this:
org.gradle.jvmargs=-Xmx4g

If you want to update your properties with either of these settings, We suggest that you put them in your <user>/.gradle/gradle.properties file so they apply to all gradle instances and so you won't accidentally check them in.

Distributions

If you don't need the absolute latest code, and would be happy with the latest binary distribution, do the following to avoid the compilation steps altogether.

  1. Download the appropriate distribution zip/tar.gz file.
  2. Put it in a directory that does not contain another file with the same extension as the distribution (.tar.gz or .zip)
  3. Use the ./gradlew :server:cleanStaging :server:cleanDeploy :server:deployDistribution command, perhaps supplying a -PdistDir=/path/to/dist/directory property value to specify the directory that contains the downloaded distribution file and/or a -PdistType=zip property to specify that you're deploying form a zip file instead of a .tar.gz file.

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all