Gradle is a build automation tool. It can automate build-related tasks such as
Managing library dependencies
Analyzing code for style compliance
The gradle configuration for this project is defined in the build script
|To learn more about gradle build scripts, refer Build Scripts Basics.|
To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this:
gradlew <task1> <task2> …e.g.
gradlew clean allTests
./gradlew <task1> <task2>…e.g.
./gradlew clean allTests
If you do not specify any tasks, Gradlew will run the default tasks
Deletes the files created during the previous build tasks (e.g. files in the
When running a Gradle task, Gradle will try to figure out if the task needs running at all. If Gradle determines that the output of the task will be same as the previous time, it will not run the task. For example, it will not build the JAR file again if the relevant source files have not changed since the last time the JAR file was built. If we want to force Gradle to run a task, we can combine that task with
addressbook.jarfile in the
build/jarfolder, if the current file is outdated.
|Why do we create a fat JAR? If we package only our own class files into the JAR file, it will not work properly unless the user has all the other JAR files (i.e. third party libraries) our classes depend on, which is rather inconvenient. Therefore, we package all dependencies into a single JAR files, creating what is also known as a fat JAR file. To create a fat JAR file, we use the Gradle plugin shadow jar.|
Converts AsciiDoc files in
docsto HTML format. Generated HTML files can be found in
Updates the offline user guide, and its associated files, used by the Help window in the application. Deployed HTML files and images can be found in
Builds and runs the application.
Builds the application as a fat JAR, and then runs it.
Runs the code style check for the main code base
Runs the code style check for the test code base
The set of code style rules implemented can be found in
config/checkstyle/checkstyle.xml. To enable exceptions to code styles, add in the comment
//CODESTYLE.OFF: RuleName at the start of the section and
//CODESTYLE.ON: RuleName at the end of the section.
Runs all tests.
Runs all tests in the
Runs all non-GUI tests in the
Sets the test mode as headless. The mode is effective for that Gradle run only so it should be combined with other test tasks.
Here are some examples:
./gradlew headless allTests— Runs all tests in headless mode
./gradlew clean nonGuiTests— Cleans the project and runs non-GUI tests
There is no need to run these Gradle tasks manually as they are called automatically by other relevant Gradle tasks.
Checks whether the project has the required dependencies to compile and run the main program, and download any missing dependencies before compiling the classes.
compilefor the list of dependencies required.
Checks whether the project has the required dependencies to perform testing, and download any missing dependencies before compiling the test classes.
testCompilefor the list of dependencies required.