The XML Formatter Gradle plugin lets you format a project’s XML files using the Liferay XML Formatter tool.
The plugin has been successfully tested with Gradle 4.10.2.
Usage
To use the plugin, include it in your build script:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.xml.formatter", version: "1.0.11"
}
repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "com.liferay.xml.formatter"
Since the plugin automatically resolves the Liferay XML Formatter library as a dependency, you have to configure a repository that hosts the library and its transitive dependencies. The Liferay CDN repository hosts them all:
repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
Tasks
The plugin adds one task to your project:
Name | Depends On | Type | Description |
---|---|---|---|
formatXML | - | FormatXMLTask | Runs the Liferay XML Formatter to format the project files. |
If the java
plugin is applied, the task formats XML files contained in the resources
directories of the main
source set
(by default: src/main/resources/**/*.xml
).
FormatXMLTask
Tasks of type FormatXMLTask
extend SourceTask
,
so all its properties and methods, such as include
and exclude
,
are available.
Task Properties
Property Name | Type | Default Value | Description |
---|---|---|---|
classpath | FileCollection | project.configurations.xmlFormatter | The classpath for executing the main class. |
mainClassName | String | "com.liferay.xml.formatter.XMLFormatter" | The fully qualified name of the XML Formatter Main class. |
stripComments | boolean | false | Whether to remove all the comments from the XML files. It sets the xml.formatter.strip.comments argument. |
Additional Configuration
There are additional configurations that can help you use the XML Formatter.
Liferay XML Formatter Dependency
By default, the plugin creates a configuration called xmlFormatter
and adds
a dependency to the latest released version of the Liferay XML Formatter. It is
possible to override this setting and use a specific version of the tool by
manually adding a dependency to the xmlFormatter
configuration:
dependencies {
xmlFormatter group: "com.liferay", name: "com.liferay.xml.formatter", version: "1.0.5"
}