groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Rocca <>
Subject Annotation on script
Date Fri, 12 Jun 2015 15:46:58 GMT
we're using groovy.util.GroovyScriptEngine to run our scripts and we 
would like to use reflection on the Script class returned by 
createScript to get the annotations declared in the script, for example:

--- script1.groovy ---
package xxxx

@CustomAnnotation("xyz", description = "aaa bbb ccc")

println "Hello world!"

--- END ---

--- ---
package xxxx;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({   ElementType.METHOD,         ElementType.TYPE,
             ElementType.CONSTRUCTOR,    ElementType.FIELD,
             ElementType.LOCAL_VARIABLE, ElementType.PACKAGE
public @interface CustomAnnotation {

     String value() default "";
     String description() default "";


--- END ---

if we execute

Script s = groovyScriptEngine.createScript("script1.groovy", new 
Binding()); // groovyScriptEngine is an instance of 

we cannot find the annotation CustomAnnotation anywhere in Script s 
(i.e.: s.getClass().getAnnotations() is empty)

Is it possible to obtain such annotation?

Thanks in advance.


View raw message