Skip to content

Conditional Compilation

Trin Wasinger edited this page Oct 20, 2026 · 6 revisions

Note

This feature only works within Groovy scripts!

Overview

Sometimes, it is beneficial to include parts of a script only under certain conditions (e.g., optional dependencies and differing client/server code). io.github.sianabeeblebrox.specter.annotation.Requires allows dropping annotated classes and methods at compile time unless a given class exists.

Examples

import io.github.sianabeeblebrox.specter.annotations.*

@Requires(name='net.minecraft.client.Minecraft')
@Transformer(name='net.minecraft.client.Minecraft')
class ClientOnlyHooks {
    // ...
}

Notes

  • The logic of Requires can be inverted to instead drop the annotated class or method if a given class does exists.
  • If multiple Requires annotations exist on the same element, it will be dropped if any one of them would cause it to be dropped.
  • Dynamic Groovy is useful for conditional control within a method (e.g., invalid references within a branch that never executes), but Requires is needed to support dropping entire methods and classes for Class Transformers.
  • For more details, see the Javadoc.

Clone this wiki locally