Integration
Annotations API
Declare in your own code what must keep its name, its signature, or stay out of some transformers.
The API is a small jar of annotations that you put on classes, methods and fields to control obfuscation where the code lives, instead of in exclusion rules. HashGuard reads them during the run and removes them from the output jar.
Add the API jar
The API jar comes with your download. It only depends on the ASM tree API. Add it as a compile-only dependency, so it is never shipped:
dependencies {
compileOnly(files("libs/hashguard-api.jar"))
} The annotations live in the fr.polargames.api.annotation package.
The annotations
| Annotation | Targets | Effect |
|---|---|---|
@KeepName | classes, methods, fields | Keeps the name. Other transformations still apply. Use it on public APIs, reflection targets and serialized fields. |
@KeepSignature | methods | Keeps the method’s name, parameter types and return type, and its MethodParameters names. Use it when a framework reads the method reflectively. |
@NoObfuscation | classes, methods, fields | Excludes the element from every transformer. On a class, it covers the class and its members. |
@ExcludeTransformers | classes, methods, fields | Excludes the element from the transformers you list. |
import fr.polargames.api.annotation.*;
@KeepName
public class PublicApi { } // class and member names preserved
class Controller {
@KeepSignature
void route(String id) { } // signature and parameter names preserved
}
@NoObfuscation
class Sensitive { } // excluded from every transformer
class Renderer {
@ExcludeTransformers({ Transformers.CONTROL_FLOW, Transformers.FLATTEN })
void hotPath() { } // excluded from those transformers only
} Transformer constants
@ExcludeTransformers takes transformer tokens. The Transformers class holds one constant per token, for example Transformers.RENAME, Transformers.STRING, Transformers.FLATTEN or Transformers.REFERENCE, plus Transformers.GLOBAL to exclude everything at once. The tokens are the same as in exclusion rules and the transformers reference. Unknown tokens are ignored.
Annotations or exclusion rules
- Use annotations for your own code: the intent sits next to the code and survives refactoring.
- Use exclusion rules for code you cannot edit: generated sources, dependencies bundled in the jar, or whole packages.
Both can be combined; an element is left alone if either one says so.