Gradle: From zero to war
The well known gradle init
task is an easy way to create a Java project:
However, there is no support for initializing a web application. Alternatively, you may use the cool gradle-templates of townsfolk: https://github.com/townsfolk/gradle-templates.
How this may be done, is described below.
Step 0: Create master gradle script
Create a master build.gradle
script. This may be done anywhere. However, I put it in the project parent directory where all my projects are found:
List the tasks:
As you can see, there are many different templates you may use. For our purpose, the createWebappProject
task seems to be interesting.
Step 1: Create the web project
Use the createWebappProject
task for creating a new fresh web project. Invoke the task and answer some questions:
Check the generated files and directories:
List the tasks:
Step 2: Create your first page and run it
Create the landing page:
And finally, run the web application in Jetty:
Open your browser http://localhost:8080/testweb/ and you should see the welcome message.
Step 3: Create war
Check if the web archive is generated:
Original post: http://peter-on-java.blogspot.com/2016/01/gradle-from-zero-to-war.html
Tags
buildtool