Building a simple Java project
To demonstrate the Java project's build with Gradle, let's create a very simple Java application that will greet a user. Just a tad bit more than a hello world
in terms of application logic.
Firstly, create a directory called hello-java
. This is our project directory. For the following steps, feel free to choose an IDE/text editor of your choice for editing the files.
Creating a build file
In the root of the project directory, let's create the build.gradle
file and add the following code line to it:
apply plugin: 'java'
Yes, that's all that goes into the build file for now, a single line. We will soon see what it means.
Adding source files
By default, like Maven, the Java source files are read from the src/main/java
directory of the project. We can configure this, of course, but let's save that for later. Let's create this directory structure in our project.
Now, we need to create a Java class that would generate the greeting...