WriteProperties

API Documentation:WriteProperties

Note: This class is incubating and may change in a future version of Gradle.

Writes a Properties in a way that the results can be expected to be reproducible.

There are a number of differences compared to how properties are stored:

  • no timestamp comment is generated at the beginning of the file
  • the lines in the resulting files are separated by a pre-set separator (defaults to '\n') instead of the system default line separator
  • the properties are sorted alphabetically

Like with Properties, Unicode characters are escaped when using the default Latin-1 (ISO-8559-1) encoding.

Properties

PropertyDescription
comment
Incubating

The optional comment to add at the beginning of the properties file.

encoding
Incubating

The encoding used to write the properties file. Defaults to ISO_8859_1. If set to anything different, unicode escaping is turned off.

lineSeparator
Incubating

The line separator to be used when creating the properties file. Defaults to `\n`.

outputFile
Incubating

The output file to write the properties to.

properties
Incubating

Returns an immutable view of properties to be written to the properties file.

Methods

MethodDescription
properties(properties)
Incubating

Adds multiple properties to be written to the properties file.

property(name, value)
Incubating

Adds a property to be written to the properties file.

Script blocks

No script blocks

Property details

String comment

Note: This property is incubating and may change in a future version of Gradle.

The optional comment to add at the beginning of the properties file.

Default:
null

String encoding

Note: This property is incubating and may change in a future version of Gradle.

The encoding used to write the properties file. Defaults to ISO_8859_1. If set to anything different, unicode escaping is turned off.

Default:
ISO-8859-1

String lineSeparator

Note: This property is incubating and may change in a future version of Gradle.

The line separator to be used when creating the properties file. Defaults to `\n`.

Default:
'\n'

File outputFile

Note: This property is incubating and may change in a future version of Gradle.

The output file to write the properties to.

Default:
null

Map<String, String> properties

Note: This property is incubating and may change in a future version of Gradle.

Returns an immutable view of properties to be written to the properties file.

Default:
[:]

Method details

void properties(Map<String, Object> properties)

Note: This method is incubating and may change in a future version of Gradle.

Adds multiple properties to be written to the properties file.

This is a convenience method for calling WriteProperties.property(java.lang.String, java.lang.Object) multiple times.

void property(String name, Object value)

Note: This method is incubating and may change in a future version of Gradle.

Adds a property to be written to the properties file.

A property's value will be coerced to a String with String#valueOf(Object) or a Callable returning a value to be coerced into a String.

Values are not allowed to be null.