Using the wrapper is the preferred way to start a build and it is a great way to ensure a reliable, controlled and standardized execution of the build in the local development environment and your CI/CD pipeline. Wrappers are avaliable for both Maven and Gradle.
One disturbing problem with wrappers is that you can't run it from a sub-module. This is because it will not find the wrapper executable since it is installed in the root of the project. The solution to that problem is to use a small function in your shell that overloads your standard maven and gradle command and that will help you locate the wrapper executable.
Below are two shell functions I'm using in my environment. Just copy and paste them into a suitable start script depending on your environment, .bashrc or .zshrc.
This is how they work:
- If it's a git repository then look for a wrapper in the toplevel directory
- If not a git repository search uppwards for a wrapper and continue to search as long as we have a pom.xml or a *.gradle file present.
- If no wrapper found, run the native builder for Maven or Gradle