Properties File Transformer
Resources transformer that merges Properties files.
The default merge strategy discards duplicate values coming from additional resources. This behavior can be changed by setting a value for the mergeStrategy property, such as MergeStrategy.First (default), MergeStrategy.Latest or MergeStrategy.Append. If the merge strategy is MergeStrategy.Latest then the last value of a matching property entry will be used. If the merge strategy is MergeStrategy.Append then the property values will be combined, using a merge separator (default value is ','). The merge separator can be changed by setting a value for the mergeSeparator property.
Say there are two properties files A and B with the following entries:
A
key1 = value1
key2 = value2
B
key2 = balue2
key3 = value3
With mergeStrategy = MergeStrategy.First you get
C
key1 = value1
key2 = value2
key3 = value3
With mergeStrategy = MergeStrategy.Latest you get
C
key1 = value1
key2 = balue2
key3 = value3
With mergeStrategy = MergeStrategy.Append and mergeSeparator = ; you get
C
key1 = value1
key2 = value2;balue2
key3 = value3
With mergeStrategy = MergeStrategy.Fail the transformation will fail if there are conflicting values.
There are three additional properties that can be set: paths, mappings, and keyTransformer. The first contains a list of strings or regexes that will be used to determine if a path should be transformed or not. The merge strategy and merge separator are taken from the global settings.
The mappings property allows you to define merge strategy and separator per path. If either paths or mappings is defined then no other path entries will be merged. mappings has precedence over paths if both are defined.
If you need to transform keys in properties files, e.g. because they contain class names about to be relocated, you can set the keyTransformer property to a closure that receives the original key and returns the key name to be used.
Example:
import org.codehaus.griffon.gradle.shadow.transformers.*
tasks.named('shadowJar', ShadowJar) {
transform(PropertiesFileTransformer) {
paths = [
'META-INF/editors/java.beans.PropertyEditor'
]
keyTransformer = { key ->
key.replaceAll('^(orig\.package\..*)$', 'new.prefix.$1')
}
}
}Related to org.apache.maven.plugins.shade.resource.properties.PropertiesTransformer.java.
Author
Andres Almiray
Marc Philipp
Properties
The character set to use when reading and writing property files. Defaults to ISO-8859-1.
This is used for creating Gradle's lazy properties in the subclass, Shadow's build-in transformers that depend on this have been injected via ObjectFactory.newInstance. Custom transformers should implement or inject this property if they need to access it.