This chapter is a work in progress
This chapter describes gradle support for Web applications. Gradle provides two plugins for Web applications: The war plug-in and the jetty plugin.
The war plugin expands the Java plugin to build your project war file.
The jetty plugin expands the war plug-in so you can deploy your Web application to an embedded jetty Web container.
Example program for this chapter:Samples/webapplication/quickstart
10.1 Building a war fileTo build a war file, you need to apply the war plugin.
Example, war plugin
Build.gradle:
Apply plugin: ' War '
This will also apply the Java plugin to your project. Run > gradle build will compile the project, test and fight the war package (the war package is in the Build/lib directory).
Gradle will include the source files under Src/main/webapp in the war file:
Web-inf/classes and Web-inf/lib directories, the compiled classes and their run-time dependencies are also included in the war file.
10.2 Running the Web application to run the Web application, apply the jetty plugin to your project:
Span style= "line-height:26px" >jetty plugin Run Web application
build.gradle:
apply plugin: ' Jetty '
This will also apply the war plugin to your project. Run > gradle jettyrun web application will run in an embedded web container jetty in
Run > gradle jettyrunwar will build the war file and run it in jetty.
Full 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
Stopport = 9451
Stopkey = ' foo '
Groovy-based Web applicationsYou can use multiple plugins in a single project, so you can work with war and Gro?? Ovy plug-ins to build a groovy-based Web application together. The appropriate Gradle library will be added to your war file.
Gradle Tutorial Description User Guide Chapter 10th Web application----Quick Start