Processor options

Compiler arguments recognised by the base processor and how to add your own.

BasicStaticProxyAnnotationProcessor declares three compiler arguments out of the box. You can read them from your own processor and you can declare new ones for processor-specific options.

Built-in options

  • -Aproxybuilder.verbose — reserved for verbose diagnostic notes.
  • -Aproxybuilder.suffix=<value> — overrides the generated class suffix globally. Takes precedence over the suffix returned by generatedClassSuffix(TypeElement).
  • -Aproxybuilder.failOnStaticMethods=true|false — defaults to true. Set to false to downgrade the “static method on a proxy target” finding to a warning so the build continues.

Wiring options into Maven

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <compilerArgs>
      <arg>-Aproxybuilder.suffix=Secured</arg>
      <arg>-Aproxybuilder.failOnStaticMethods=true</arg>
    </compilerArgs>
  </configuration>
</plugin>

Adding your own option

Your processor inherits the standard SupportedOptions/getSupportedOptions() contract from javax.annotation.processing.Processor. Override getSupportedOptions() to declare additional keys, then read them through processingEnv.getOptions():

@Override
public Set<String> getSupportedOptions() {
  Set<String> opts = new HashSet<>(super.getSupportedOptions());
  opts.add("myproject.audit.target");
  return opts;
}

private String auditTarget() {
  return processingEnv.getOptions()
      .getOrDefault("myproject.audit.target", "console");
}

Tips

  • Stay namespaced. Prefix your option keys with your project (myproject.…) so they do not collide with proxybuilder.….
  • Document the defaults. Pre-Maven-4 builds often have a different compilerArgs syntax — be explicit about what each option does in your own README so users do not need to read the processor source.
  • Fail loudly on typos. If a user passes -Amyproject.audi.target=… by mistake, you will silently fall back to the default. A note from processingEnv.getMessager() at the start of the processing round is cheap insurance.

Edit this page on GitHub ↗