0

I would like to enforce static linking for a whole package in groovy. Static linking requires use of CompileStatic. I would like to avoid restating this on every class. How can I apply this as a package-level annotation. I have found no reference to package-level annotations in groovy.

Can you please provide a piece of code that shows how to apply the annotation to a package a.b.c?

Jörn Guy Süß
  • 1,408
  • 11
  • 18
  • Have you read any where that the mentioned annotation can be applied to package? Hence the question posted? – Rao Sep 15 '17 at 02:49

1 Answers1

1

This is untested, but I think it should be possible to create a nice combination of a configurationScript, a Source aware customizer and a AST transformation customizer explained in dsl docs.

something like:

withConfig(configuration) {
    source(unitValidator: { unit -> unit.AST.classes.any { it.packageName== 'a.b.c' } }) {
        ast(CompileStatic) 
    }
}
andi
  • 361
  • 1
  • 4
  • 10
  • haha, tested it and it worked! :) Of course, use packageName.startsWith('a.b.c') to include subpackages. – andi Sep 15 '17 at 16:17