api / org.gradle.api.tasks / WriteProperties

WriteProperties

@CacheableTask open class WriteProperties : DefaultTask

Writes a java.util.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:

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

See Also
java.util.Properties#store(OutputStream, String)

Since
3.3

Constructors

<init>

WriteProperties()

Writes a java.util.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 java.util.Properties, Unicode characters are escaped when using the default Latin-1 (ISO-8559-1) encoding.

Functions

getComment

open fun getComment(): String

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

getEncoding

open fun getEncoding(): String

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

getLineSeparator

open fun getLineSeparator(): String

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

getOutputFile

open fun getOutputFile(): File

Returns the output file to write the properties to.

getProperties

open fun getProperties(): MutableMap<String, String>

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

properties

open fun properties(properties: MutableMap<String, Any>): Unit

Adds multiple properties to be written to the properties file.

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

property

open fun property(name: String, value: Any): Unit

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.

setComment

open fun setComment(comment: String): Unit

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

setEncoding

open fun setEncoding(encoding: String): Unit

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

setLineSeparator

open fun setLineSeparator(lineSeparator: String): Unit

Sets the line separator to be used when creating the properties file.

setOutputFile

open fun setOutputFile(outputFile: File): Unit
open fun setOutputFile(outputFile: Any): Unit

Sets the output file to write the properties to.

setProperties

open fun setProperties(properties: MutableMap<String, Any>): Unit

Sets all properties to be written to the properties file replacing any existing properties.

writeProperties

open fun writeProperties(): Unit