Build Tools (Gradle)
Installation
Refer to the installation notes for full install details. In summary, install the gradle
package:
$ yay -S gradle
Setting up a Java Gradle Project
This will be following the documentation for setting up a new java project.
-
Create a new project directory:
$ mkdir demo $ cd demo
-
Make a new gradle project using the step-by-step wizard.
$ gradle init
- For project type choose application (2).
- As implementation language chose Java (3).
- As test framework select “JUnit Jupiter” (4).
- For the other questions just select the default value.
- Several files and a folder hierarchy are created. This includes a simple “Hello World” program.
-
To test, build and run your code execute in the root of the project:
$ ./gradlew run
The program is run after the output:
> Task :run
Gradle Tasks
Gradle has has several tasks:
-
To clean the project directory:
$ ./gradlew clean
This will remove all compiler class files.
-
To compile but not run your project:
$ ./gradlew compileJava
This will compiler all java source files in
app/src/main/java
and output the compiler bytecode intoapp/build/main
.
To view additional help run:
$ ./gradlew help