concept Java plugin in category gradle

This is an excerpt from Manning's book Gradle in Action - corrected 9052019.
The Java plugin is a small opinionated framework. It assumes sensible default values for many aspects of your project, like its layout. If your view of the world is different, Gradle gives you the option of customizing the conventions. How do you know what’s configurable? A good place to start is Gradle’s Build Language Reference, available at http://www.gradle.org/docs/current/dsl/. Remember the command-line option properties from chapter 2? Running gradle properties gives you a list of configurable standard and plugin properties, plus their default values. You’ll customize the project by extending the initial build script.
I already mentioned that the War plugin extends the Java plugin. In practice, this means that you don’t have to apply the Java plugin anymore in your build script. It’s automatically brought in by the War plugin. Note that even if you applied the Java plugin as well, there would be no side effect on your project. Applying plugins is an idempotent operation, and therefore is only executed once for a specific plugin. When creating your build.gradle file, use the plugin like this:
apply plugin: 'war'What exactly does that mean to your project? In addition to the conventions provided by the Java plugin, your project becomes aware of a source directory for web application files and knows how to assemble a WAR file instead of a JAR file. The default convention for web application sources is the directory src/main/webapp. With all the web resource files in the right location, your project layout should look like this:
One line of code is enough to build your Java code, but how does Gradle know where to find your source files? One of the conventions the Java plugin introduces is the location of the source code. By default, the plugin searches for production source code in the directory src/main/java. You’ll take all the classes of your To Do application and put them under the appropriate directory.
You’re ready to build the project. One of the tasks the Java plugin adds to your project is named build. The build task compiles your code, runs your tests, and assembles the JAR file, all in the correct order. Running the command gradle build should give you an output similar to this:
![]()
Each line of the output represents an executed task provided by the Java plugin. You may notice that some of the tasks are marked with the message UP-TO-DATE. That means that the task was skipped. Gradle’s incremental build support automatically identified that no work needed to be done. Especially in large enterprise projects, this feature proves to be a real timesaver. In chapter 4 you’ll learn how to apply this concept to your own tasks. In the command-line output, you can see concrete examples of skipped tasks: compileTestJava and testClasses. As you didn't provide any unit tests in the default directory src/test/java, Gradle happily moves on. If you want to learn how to write tests for your application and integrate them into the build, see chapter 7. Here’s the project structure after executing the build: