Skip to content

Exclusion Rules ​

Exclusion rules specify which classes, methods, or fields should NOT be obfuscated. While Bozar generally handles standard reflection automatically, exclusions are essential for dynamic reflection (where names are constructed at runtime), serialization, and certain frameworks.

Syntax Overview ​

Enter one rule per line using the following prefixes:

  • class: - Matches classes
  • method: - Matches methods
  • field: - Matches fields
  • ! - Inverts the rule (include instead of exclude)
  • # - Comments

Class Exclusions ​

Use class: followed by the class name pattern.

Exact Match ​

class: com.example.Main
class: com.example.api.UserService

Wildcard Patterns ​

PatternMatchesExample
*Any single package levelclass: com.example.*
**Any number of package levelsclass: com.example.**
?Any single characterclass: com.example.User?
!Invert rule (include)!class: com.example.Internal

Inverting Rules ​

You can use the exclamation mark ! to invert a rule. This is useful when you want to exclude a package but keep a specific class within it obfuscated (or vice-versa, depending on your default strategy).

# Exclude everything in com.example
class: com.example.**

# But keep com.example.SecretClass obfuscated (force include)
!class: com.example.SecretClass

Examples ​

# All classes in com.example package (not subpackages)
class: com.example.*

# All classes in com.example and all subpackages
class: com.example.**

# All classes ending with "Controller"
class: **.*Controller

Method and Field Exclusions ​

Use method: or field: to exclude class members.

# Exclude methods starting with 'get'
method: get*

# Exclude specific field
field: serialVersionUID

# Exclude methods with specific signature (advanced)
method: process(Ljava/lang/String;)V

Common Framework Exclusions ​

Serialization ​

Classes that are serialized (e.g., to JSON or binary) usually need their names and fields preserved.

class: com.example.dto.**
class: com.example.model.**

Maven Plugin Configuration ​

When using the Maven Plugin, exclusions are configured directly in XML — no prefix syntax needed:

xml
<exclusions>
  <classes>
    <class>com.example.dto.**</class>
    <class>com.example.model.**</class>
  </classes>
  <methods>
    <method>get*()</method>
    <method>set*()</method>
  </methods>
  <fields>
    <field>serialVersionUID</field>
    <field>SECRET_*</field>
  </fields>
</exclusions>

Each section is optional — include only what you need. The same wildcard patterns (*, **, ?, !) apply.