Gradle is a higly customizable, powerful and fast build system.
Let's walk through a simple example to configure a project using gradle.
First, download a specific release.
Here are the steps to configure it.
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-7.2-bin.zip
$ ls /opt/gradle/gradle-7.2/
LICENSE NOTICE README bin init.d lib
Add the following line in ~/.bashrc
.
export PATH=$HOME/.local/bin:$PATH
~/.bashrc
file should be updated to get the changes.
$ source ~/.bashrc
Run gradle -version
when the above steps are completed.
Let's call the project name blue
and scaffold gradle for it.
$ mkdir blue
$ cd blue
$ gradle init
It will ask few to setup the directory strucutre
Select type of project to generate:
1. basic
2. application
3. library
4. Gradle plugin
For this example, let's select 2. application
.
The following question will ask selecting the implementation language which I choose java
.
The other options could be selected as per the given default choice.
Let's create a makefile
and add some basic gradle commands there.
$ cat makefile
JAVA_HOME = /opt/sun/jdk15
GRADLE_HOME = /opt/gradle/gradle-7.2
GRADLE = $(GRADLE_HOME)/bin/gradle
clean:
./gradlew clean
build:
./gradlew build
run:
./gradlew run
test:
gradle test --tests AppTest
App.java
which is located in app/src/main/java/blue/
is the entry point to the project.
Edit this class and add soem message to it.
package blue;
public class App {
private String getMessage() { return "My Gradle Project"; }
public static void main(String[] args) {
App app = new App();
System.out.println(app.getMessage());
}
}
Now, run the project.
$ make build
$ make run
The sample message should be printed in the console if the build is successful.
Download this sample.
Top comments (0)