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

26

The War Plugin

The War plugin extends the Java plugin to add support for assembling web application WAR files. It disables the default JAR archive generation of the Java plugin and adds a default WAR archive task.

26.1. Usage

To use the War plugin, include in your build script:

Example 26.1. Using the War plugin

build.gradle

apply plugin: 'war'

26.2. Tasks

The War plugin adds the following tasks to the project.

Table 26.1. War plugin - tasks

Task name

Depends on

Type

Description

war

compile

War

Assembles the application WAR file.

The War plugin adds the following dependencies to tasks added by the Java plugin.

Table 26.2. War plugin - additional task dependencies

Task name

Depends on

assemble

war

Page 167 of 343

[11]

Figure 26.1. War plugin - tasks

26.3. Project layout

Table 26.3. War plugin - project layout

Directory

Meaning

src/main/webapp Web application sources

26.4. Dependency management

The War plugin adds two dependency configurations: providedCompile and providedRuntime

. Those configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you addcommons-httpclient:commons-h to any of the provided configurations. This dependency has a dependency on commons-codec. This means neither httpclient nor commons-codec is added to your WAR, even if commons-c were an explicit dependency of your compile configuration. If you don't want this transitiv behavior, simply declare your provided dependencies like commons-httpclient:commons-ht

.

26.5. Convention properties

Table 26.4. War plugin - directory properties

Property name

Type

Default value

Description

webAppDirName

String

src/main/webapp

The name of the web application

 

 

 

source directory, relative to the

 

 

 

project directory.

webAppDir

File

projectDir/webAppDirNameThe

application source

 

(read-only)

 

directory.

 

These properties are provided by a WarPluginConvention convention object.

26.6. War

The default behavior of the War task is to copy the content of src/main/webapp to the root of the archive. Your webapp directory may of course contain a WEB-INF sub-directory, which again may contain a web.xml file. Your compiled classes are compiled to WEB-INF/classes. All the dependencies of the runtime configuration are copied to WEB-INF/lib.

Page 168 of 343

Have also a look at War.

26.7. Customizing

Here is an example with the most important customization options:

Example 26.2. Customization of war plugin

build.gradle

configurations { moreLibs

}

repositories {

flatDir { dirs "lib" } mavenCentral()

}

dependencies {

compile module(":compile:1.0") {

dependency ":compile-transitive-1.0@jar" dependency ":providedCompile-transitive:1.0@jar"

}

providedCompile "javax.servlet:servlet-api:2.5" providedCompile module(":providedCompile:1.0") {

dependency ":providedCompile-transitive:1.0@jar"

}

runtime ":runtime:1.0"

providedRuntime ":providedRuntime:1.0@jar" testCompile "junit:junit:4.8.2"

moreLibs ":otherLib:1.0"

}

war {

from 'src/rootContent' // adds a file-set to the root of the archive webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF d classpath fileTree('additionalLibs') // adds a file-set to the WEB-INF/lib classpath configurations.moreLibs // adds a configuration to the WEB-INF/l webXml = file('src/someWeb.xml') // copies a file to WEB-INF/web.xml

}

Of course one can configure the different file-sets with a closure to define excludes and includes.

[11] The runtime configuration extends the compile configuration.

Page 169 of 343

27

The Ear Plugin

The Ear plugin adds support for assembling web application EAR files. It adds a default EAR archive task. It doesn't require the Java plugin, but for projects that also use the Java plugin disables the default JAR archive generation.

27.1. Usage

To use the Ear plugin, include in your build script:

Example 27.1. Using the Ear plugin

build.gradle

apply plugin: 'ear'

27.2. Tasks

The Ear plugin adds the following tasks to the project.

Table 27.1. Ear plugin - tasks

Task

Depends on

Type

Description

name

 

 

 

ear

compile (only if the Java plugin is also

Ear

Assembles the application

 

applied)

 

EAR file.

The Ear plugin adds the following dependencies to tasks added by the base plugin.

Table 27.2. Ear plugin - additional task dependencies

Task name

Depends on

assemble

ear

Page 170 of 343

27.3. Project layout

Table 27.3. Ear plugin - project layout

Directory

Meaning

src/main/application Ear resources, such as a META-INF directory

27.4. Dependency management

The Ear plugin adds two dependency configurations: deploy and earlib. All dependencies in the deploy configuration are placed in the root of the EAR archive, and are <em>not</em> transitive. All dependencies in the earlib configuration are placed in the 'lib' directory in the E archive and <em>are</em> transitive.

27.5. Convention properties

Table 27.4. Ear plugin - directory properties

Property name

Type

appDirName

String

libDirName String

deploymentDescriptor org.gradle.plugins.ear.descriptor.DeploymentDescr

These properties are provided by a EarPluginConvention convention object.

27.6. Ear

The default behavior of the Ear task is to copy the content of src/main/application to the root of the archive. If your application directory doesn't contain aMETA-INF/application.xml deployment descriptor then one will be generated for you.

Also have a look at Ear.

Page 171 of 343

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