Skip to content
Yoom Lam edited this page Jun 20, 2023 · 9 revisions

Gradle is used to specify Java dependencies, lint code, compile code, build Docker images, etc.

There's lots of tutorials online. Here are some tips:

Bash alias

Since it's used frequently, a Bash alias is useful (alias g='$PWD/gradlew'), which reduces typing g build. (The $PWD enables g to be run from any folder.)

Additional aliases can be created:

alias g="$PWD/gradlew"
alias delint='g spotlessApply'
alias gbuild='delint && g build'
alias gdocker='g build && g docker'
alias gcdocker='g clean && gdocker'

alias gdcDown='g dockerComposeDown'
alias gdcUp='g dockerComposeUp'
alias gdcRestart='g dockerComposeDown dockerComposeUp'

Important Files to Review

  • settings.gradle: includes subdirectories as Gradle subprojects
  • build.gradle in the project root, api, and app subdirectories
  • buildSrc subdirectory: LHDI Starter Kit provides Gradle plugins; details in the README.md.

Gradle library dependencies

To see the current dependencies between subprojects, navigate to the root of the repo and run: ./gradlew :<GRADLE_PROJECT_NAME>:dependencies --configuration compileClasspath | grep "project :"

To see all (including 3rd-party) of the dependencies for a gradle subproject run: ./gradlew :<GRADLE_PROJECT_NAME>:dependencies --configuration compileClasspath > deps.txt

This command will print the dependency tree for the supplied subproject to the deps.txt file.

Gradle tasks

  • ./gradlew tasks
  • ./gradlew tasks --all

https://gitlab.com/barfuin/gradle-taskinfo:

  • ./gradlew tiTree assemble
  • ./gradlew tiOrder docker

buildSrc

If you're looking for a buildSrc folder, use the gradle-plugins folder instead -- it functions equivalently but is reusable and results in faster builds.

Composite Builds

The codebase use Composite Builds to partition and decouple Gradle projects, resulting in faster builds.

The current composite builds are:

  • gradle-plugins: only used for building the code; this is included by other Gradle projects
  • mocks: for projects that represent external APIs or services
  • (root): the main VRO codebase

A composite build is built independently unless it is referenced by an includeBuild in settings.gradle. For example, since gradle-plugins is included by other Gradle projects, it is re-built automatically when it changes. However, mocks will not be rebuilt unless the Gradle build task is explicitly run against mocks folder ./gradlew -p mocks build or:

cd mocks
./gradlew build

Since mocks rarely need to be rebuilt (and are not integral to the deployed VRO), this will reduce build time.

Clone this wiki locally