Configuration
Exclusion rules
Keep classes, methods and fields away from every transformer or from specific ones.
Exclusion rules tell HashGuard what to leave alone. They live in the exclude key of the configuration, as a single string with one rule per line:
{
"exclude": "com.example.api.**\nflatten:com.example.render.**\nrename:com.example.Main**"
} Use them for code you cannot annotate, such as generated code or classes reached by name from configuration files. In your own code, annotations are usually clearer.
Rule format
[<token>:][!]<pattern> | Part | Meaning |
|---|---|
<token>: | Optional. Limits the rule to one transformer, using its token, for example flatten: or rename:. global: or no prefix applies the rule to every transformer. |
! | Optional. Turns the rule into a re-inclusion: what it matches is protected again, even inside a broader exclusion. |
<pattern> | The class, method or field to match, with dots as separators. |
Empty lines and lines starting with # are ignored.
Patterns
Patterns are matched against names written with dots:
| Subject | Written as |
|---|---|
| A class | com.example.Main |
| A method | com.example.Main.run() |
| A field | com.example.Main.config |
Nested classes follow their outer class: a rule on com.example.Main also covers Main$Inner.
| Pattern | Matches |
|---|---|
com.example.Main | Exactly that name. |
com.example.* | Names that start with com.example. at the same depth: the classes of the package, not its sub-packages. |
com.example.** | Everything under com.example, at any depth. |
com.example.Main** | The class and all of its members. |
*Test or **Test | Names that end with Test. |
Examples
Keep a public API readable, but still encrypt its strings:
rename:com.example.api.** Leave a package out of everything, except one class:
com.example.legacy.**
!com.example.legacy.LicenceCheck Keep the hot rendering code out of the expensive control-flow passes only:
flatten:com.example.render.**
controlFlow:com.example.render.** Exclude a method that is called through reflection:
rename:com.example.plugins.Loader.load() How rules combine
- A subject is excluded from a transformer when at least one rule for that transformer, or a global rule, matches it.
- A matching re-inclusion (
!) always wins over exclusions, wherever it sits in the list. - Rules are evaluated against the original names, so they keep working after renaming.