Using the Java plugin
To work with the Java plugin, we are first going to create a very simple Java source file. We can then use the plugin's tasks to build the source file. You can make this application as complex as you wish, but in order to stay on topic, we will make this as simple as possible.
By applying the Java plugin, we must now follow some conventions for our project directory structure. To build the source code, our Java source files must be in the src/main/java
directory, relative to the project directory. If we have non-Java source files that need to be included in the JAR file, we must place them in the directory src/main/resources
. Our test source files need to be in the src/test/java
directory, and any non-Java source files needed for testing can be placed in src/test/resources
. These conventions can be changed if we want or need it, but it is a good idea to stick to them so we don't have to write any extra code in our build file, which could cause errors.
Our sample Java...