Gradle tutorial description Chapter 1 Web applications-Quick Start and gradle Quick Start
This chapter is an ongoing work
This chapter describes Gradle support for Web applications. Gradle provides two plug-ins for Web applications: War plug-ins and Jetty plug-ins.
The War plugin extends the Java Plugin to build your project WAR file.
The Jetty plugin extends the War plugin so that you can deploy your Web application to an embedded Jetty Web container.
Sample programs in this chapter: samples/webApplication/quickstart
10.1 to build a WAR file, you must apply the WAR plug-in.
Example: war plug-in
Build. gradle:
Apply plugin: 'War'
This also applies Java Plug-ins to your project. Run> gradle build to compile, test, and compress the project (the WAR package is under the build/lib directory ).
Gradle will include the source code file under src/main/webapp in the WAR file:
Under the WEB-INF/classes and WEB-INF/lib directories, compiled classes and their runtime dependencies are also included in the WAR file.
10.2 To run a Web application, run the Web application and apply the Jetty plug-in to your project:
For example, run the Web application using the Jetty plug-in.
Build. gradle:
Apply plugin: 'jetty'
This also applies the War plug-in to your project. Run> gradle jettyRun Web application will run in the embedded Web Container Jetty.
Run> gradle jettyRunWar to build the WAR file and then run it in Jetty.
Complete build. gradle:
Apply plugin: 'War'
Apply plugin: 'jetty'
Repositories {
MavenCentral ()
}
Dependencies {
Compile group: 'commons-io ', name: 'commons-io', version: '1. 4'
Compile group: 'log4j ', name: 'log4j', version: '1. 2.15 ', ext: 'jar'
}
HttpPort = 8080
Stopports = 9451
StopKey = 'foo'
Groovy-based Web applications you can use multiple plug-ins in a single project, so you can use the War and Groovy plug-ins to create a Groovy-based Web application. The appropriate Gradle library will be added to your WAR file.