Package org.gradle.api.tasks

## Class WriteProperties

- java.lang.Object
- - org.gradle.api.internal.AbstractTask
  - - org.gradle.api.DefaultTask
    - - org.gradle.api.tasks.WriteProperties

- All Implemented Interfaces:
    `java.lang.Comparable<Task>`, `org.gradle.api.internal.DynamicObjectAware`, `org.gradle.api.internal.TaskInternal`, `ExtensionAware`, `Task`, `Configurable<Task>`

      @CacheableTask
      public abstract class WriteProperties
      extends DefaultTask

  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.

  Since:
    3.3
  See Also:
    `Properties.store(OutputStream, String)`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.gradle.api.Task

      `Task.Namer`

  - ### Field Summary

    - ### Fields inherited from interface org.gradle.api.Task

      `TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `WriteProperties()` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `java.lang.String` | `getComment()` | Returns the optional comment to add at the beginning of the properties file.
    `abstract RegularFileProperty` | `getDestinationFile()` | The output properties file.
    `java.lang.String` | `getEncoding()` | Returns the encoding used to write the properties file.
    `java.lang.String` | `getLineSeparator()` | Returns the line separator to be used when creating the properties file.
    `java.io.File` | `getOutputFile()` | Deprecated.
    `java.util.Map<java.lang.String,​java.lang.String>` | `getProperties()` | Returns an immutable view of properties to be written to the properties file.
    `void` | `properties​(java.util.Map<java.lang.String,​java.lang.Object> properties)` | Adds multiple properties to be written to the properties file.
    `void` | `property​(java.lang.String name, java.lang.Object value)` | Adds a property to be written to the properties file.
    `void` | `setComment​(java.lang.String comment)` | Sets the optional comment to add at the beginning of the properties file.
    `void` | `setEncoding​(java.lang.String encoding)` | Sets the encoding used to write the properties file.
    `void` | `setLineSeparator​(java.lang.String lineSeparator)` | Sets the line separator to be used when creating the properties file.
    `void` | `setOutputFile​(java.io.File outputFile)` | Deprecated.
    `void` | `setOutputFile​(java.lang.Object outputFile)` | Deprecated.
    `void` | `setProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties)` | Sets all properties to be written to the properties file replacing any existing properties.
    `void` | `writeProperties()` |

    - ### Methods inherited from class org.gradle.api.DefaultTask

      `compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService`

    - ### Methods inherited from class org.gradle.api.internal.AbstractTask

      `acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.gradle.api.Task

      `doNotTrackState, getConvention, notCompatibleWithConfigurationCache`

- - ### Constructor Detail

    - #### WriteProperties

          public WriteProperties()

  - ### Method Detail

    - #### getProperties

          @Input
          public java.util.Map<java.lang.String,​java.lang.String> getProperties()

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

    - #### setProperties

          public void setProperties​(java.util.Map<java.lang.String,​java.lang.Object> properties)

      Sets all properties to be written to the properties file replacing any existing properties.
      See Also:
        `properties(Map)`, `property(String, Object)`

    - #### property

          public void property​(java.lang.String name,
                               java.lang.Object value)

      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.

      Parameters:
        `name` - Name of the property
        `value` - Value of the property
      Since:
        3.4

    - #### properties

          public void properties​(java.util.Map<java.lang.String,​java.lang.Object> properties)

      Adds multiple properties to be written to the properties file.

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

      Parameters:
        `properties` - Properties to be added
      Since:
        3.4
      See Also:
        `property(String, Object)`

    - #### getLineSeparator

          @Input
          public java.lang.String getLineSeparator()

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

    - #### setLineSeparator

          public void setLineSeparator​(java.lang.String lineSeparator)

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

    - #### getComment

          @Nullable
          @Optional
          @Input
          public java.lang.String getComment()

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

    - #### setComment

          public void setComment​(@Nullable
                                 java.lang.String comment)

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

    - #### getEncoding

          @Input
          public java.lang.String getEncoding()

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

    - #### setEncoding

          public void setEncoding​(java.lang.String encoding)

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

    - #### getOutputFile

          @Internal
          @Deprecated
          public java.io.File getOutputFile()

      Deprecated.
      Returns the output file to write the properties to.

    - #### setOutputFile

          @Deprecated
          public void setOutputFile​(java.io.File outputFile)

      Deprecated.
      Sets the output file to write the properties to.
      Since:
        4.0

    - #### setOutputFile

          @Deprecated
          public void setOutputFile​(java.lang.Object outputFile)

      Deprecated.
      Sets the output file to write the properties to.

    - #### getDestinationFile

          @OutputFile
          public abstract RegularFileProperty getDestinationFile()

      The output properties file.
      Since:
        8.1

    - #### writeProperties

          public void writeProperties()
                               throws java.io.IOException

      Throws:
        `java.io.IOException`