Gradle and CI/CD Pipeline: General approach?


I’m setting up a CI/CD Pipeline using Gradle (using Java and a React frontend). I’m quite new to Gradle. The current pipeline basically does something like this:

  1. gradle build
  2. gradle test
  3. gradle checkstyleMain

The problem with this approach is that each stage runs the entire build again. So I went about and changed it to:

  1. gradle assemble
  2. gradle test
  3. gradle checkstyleMain

The problem with gradle test and gradle checkstyleMain is though that they also automatically execute all tasks before them. This seems like something very basic I’m missing. Is it not common to build/assemble everything in the first stage and then reuse those binaries/assets to execute tests etc.? How do people usually go about this? Do people really exclude all tasks explicitly, e.g. gradle test -x compileJava or something?

Any help / best practices on how to properly design such a basic pipeline would be appreciated.

Usually you just do gradlew build.
build depends on assemble and check.
check depends on test and checkstyleMain and other check tasks of plugins you applied.
So just invoking build should already do everything you need in one go.

Besides that, if you do it in these three steps, the tasks will be investiated again, yes.
But they will usually not execute again…
Unless your build script does bad things, breaking incremental building, your step 2 and 3 should not really do anything but just see that all tasks are up-to-date.
Gradle is pretty good in avoiding unnecessary work.