ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 01.01.2026
Просмотров: 1152
Скачиваний: 0
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
27.7. Customizing
Here is an example with the most important customization options:
Example 27.2. Customization of ear plugin
build.gradle
apply plugin: 'ear' apply plugin: 'java'
repositories { mavenCentral() }
dependencies {
//following dependencies will become the ear modules and placed in the ear deploy project(':war')
//following dependencies will become ear libs and placed in a dir configur earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}
ear {
appDirName 'src/main/app' // use application metadata found in this folde libDirName 'APP-INF/lib' // put dependency libraries into APP-INF/lib ins // also modify the generated deployment descri
deploymentDescriptor { // custom entries for application.xml:
//fileName = "application.xml" // same as the default value
//version = "6" // same as the default value applicationName = "customear" initializeInOrder = true
displayName = "Custom Ear" // defaults to project.name
description = "My customized EAR for the Gradle documentation" // def
//libraryDirectory = "APP-INF/lib" // not needed, because setting libDi
//module("my.jar", "java") // wouldn't deploy since my.jar isn't a depl
//webModule("my.war", "/") // wouldn't deploy since my.war isn't a depl securityRole "admin"
securityRole "superadmin"
withXml { provider -> // add a custom node to the XML provider.asNode().appendNode("data-source", "my/data/source")
}
}
}
You can also use customization options that the Ear task provides, such as from and metaInf.
27.8. Using custom descriptor file
Let's say you already have theapplication.xml and want to use it instead of configuring the ea section. To accommodate that place the META-INF/application.xml in the right place inside your source folders (see the appDirName property). The existing file contents will be used and the explicit configuration in the ear.deploymentDescriptor will be ignored.
Page 172 of 343
28
The Jetty Plugin
The Jetty plugin extends the War plugin to add tasks which allow you to deploy your web application to a Jetty web container embedded in the build.
28.1. Usage
To use the Jetty plugin, include in your build script:
Example 28.1. Using the Jetty plugin
build.gradle
apply plugin: 'jetty'
28.2. Tasks
The Jetty plugin defines the following tasks:
Table 28.1. Jetty plugin - tasks
Task name |
Depends |
Type |
Description |
|
on |
|
|
jettyRun |
compile |
JettyRun |
Starts a Jetty instance and deploys the |
|
|
|
exploded web application to it. |
jettyRunWar |
war |
JettyRunWar |
Starts a Jetty instance and deploys the WAR |
|
|
|
to it. |
jettyStop |
- |
JettyStop |
Stops the Jetty instance. |
Page 173 of 343
Figure 28.1. Jetty plugin - tasks
28.3. Project layout
The Jetty plugin uses the same layout as the War plugin.
28.4. Dependency management
The Jetty plugin does not define any dependency configurations.
28.5. Convention properties
The Jetty plugin defines the following convention properties:
Table 28.2. Jetty plugin - properties
Property |
Type |
Default |
Description |
name |
|
value |
|
httpPort |
Integer |
8080 |
The TCP port which Jetty should listen for HTTP |
|
|
|
requests on. |
stopPort |
Integer |
null |
The TCP port which Jetty should listen for admin |
|
|
|
requests on. |
stopKey |
String |
null |
The key to pass to Jetty when requesting it to |
|
|
|
stop. |
These properties are provided by a JettyPluginConvention convention object.
Page 174 of 343
29
The Checkstyle Plugin
The Checkstyle plugin performs quality checks on your project's Java source files usingCheckstyle and generates reports from these checks.
29.1. Usage
To use the Checkstyle plugin, include in your build script:
Example 29.1. Using the Checkstyle plugin
build.gradle
apply plugin: 'checkstyle'
The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running gradle check.
29.2. Tasks
The Checkstyle plugin adds the following tasks to the project:
Table 29.1. Checkstyle plugin - tasks
Task name |
Depends on |
Type |
Description |
checkstyleMain |
classes |
Checkstyle |
Runs Checkstyle against the |
|
|
|
production Java source files. |
checkstyleTest testClasses Checkstyle
checkstyleSourceSetsourceSetClassCheckstylees
Runs Checkstyle against the test Java source files.
Runs Checkstyle against the given source set's Java source files.
The Checkstyle plugin adds the following dependencies to tasks defined by the Java plugin.
Page 175 of 343