Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Gradle.pdf
Скачиваний:
9
Добавлен:
24.03.2015
Размер:
1.4 Mб
Скачать

10

Web Application Quickstart

This chapter is a work in progress.

This chapter introduces some of the Gradle's support for web applications. Gradle provides tw plugins for web application development: the War plugin and the Jetty plugin. The War plugin extends the Java plugin to build a WAR file for your project. The Jetty plugin extends the War plugin to allow you to deploy your web application to an embedded Jetty web container.

10.1. Building a WAR file

To build a WAR file, you apply the War plugin to your project:

Example 10.1. War plugin

build.gradle

apply plugin: 'war'

Note: The code for this example can be found at samples/webApplication/quickstart which is in both the binary and source distributions of Gradle.

This also applies the Java plugin to your project. Running gradle build will compile, test and WAR your project. Gradle will look for the source files to include in the WAR file in src/main/web

. Your compiled classes, and their runtime dependencies are also included in the WAR file.

10.2. Running your web application

To run your web application, you apply the Jetty plugin to your project:

Groovy web applications

You can combine multiple plugins in a single project, so you can use the War and Groovy plugins together to build a Groovy based web

Page 53 of 343

Example 10.2. Running web application with Jetty plugin

application. The appropriate

build.gradle

groovy libraries will be added

to the WAR file for you.

 

apply plugin: 'jetty'

 

This also applies the War plugin to your project. Running gradle jettyRun will run your web application in an embedded Jetty web container. Running gradle jettyRunWar will build the WAR file, and then run it in an embedded web container.

TODO: which url, configure port, uses source files in place and can edit your files and reload.

10.3. Summary

You can find out more about the War plugin in Chapter 26, The War Plugin and the Jetty plugin in Chapter 28, The Jetty Plugin. You can find more sample Java projects in the samples/webAppli directory in the Gradle distribution.

Page 54 of 343

11

Using the Gradle Command-Line

This chapter introduces the basics of the Gradle command-line. You run a build using the gradle command, which you have already seen in action in previous chapters.

11.1. Executing multiple tasks

You can execute multiple tasks in a single build by listing each of the tasks on the command-line. For example, the command gradle compile test will execute the compile and test tasks. Gradle will execute the tasks in the order that they are listed on the command-line, and will also execute the dependencies for each task. Each task is executed once only, regardless of how it came to be included in the build: whether it was specified on the command-line, or it a dependency of another task, or both. Let's look at an example.

Below four tasks are defined. Both dist and test depend on the compile task. Running gradle for this build script results in the compile task being executed only once.

Figure 11.1. Task dependencies

Page 55 of 343

Example 11.1. Executing multiple tasks

build.gradle

task compile << {

println 'compiling source'

}

task compileTest(dependsOn: compile) << { println 'compiling unit tests'

}

task test(dependsOn: [compile, compileTest]) << { println 'running unit tests'

}

task dist(dependsOn: [compile, test]) << { println 'building the distribution'

}

Output of gradle dist test

> gradle dist test :compile

compiling source :compileTest compiling unit tests :test

running unit tests :dist

building the distribution

BUILD SUCCESSFUL

Total time: 1 secs

Because each task is executed once only, executing gradle test test is exactly the same as executing gradle test.

11.2. Excluding tasks

You can exclude a task from being executed using the -x name of the task to exclude. Let's try this with the sample

command-line option and providing the build file above.

Page 56 of 343

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]