Package groovy.lang

Annotation Type GrabConfig


  • @Retention(SOURCE)
    @Target({CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PARAMETER,TYPE})
    public @interface GrabConfig
    Used to modify the grape configuration for grab requests.

    An example involving databases:

     @Grab('mysql:mysql-connector-java:5.1.6')
     @GrabConfig(systemClassLoader=true)
     import groovy.sql.Sql
    
     def sql=Sql.newInstance("jdbc:mysql://localhost/test", "user", "password", "com.mysql.jdbc.Driver")
     println sql.firstRow('SELECT * FROM INFORMATION_SCHEMA.COLUMNS')
     
    Another example involving XStream:
     @Grab('com.thoughtworks.xstream:xstream:1.4.9')
     @Grab('xpp3:xpp3_min:1.1.4c')
     @GrabConfig(systemClassLoader=true, initContextClassLoader=true)
     
     import com.thoughtworks.xstream.*
    
     class Staff {
         String firstname, lastname, position
     }
    
     def xstream = new XStream()
     def john1 = new Staff(firstname:'John',
                          lastname:'Connor',
                          position:'Resistance Leader')
    
     // write out to XML file
     new File("john.xml").withOutputStream { out ->
         xstream.toXML(john1, out)
     }
    
     // now read back in
     def john2
     new File("john.xml").withInputStream { ins ->
         john2 = xstream.fromXML(ins)
     }
    
     println john2.dump()
     
     

    Further information about customising grape behavior can be found on the Grape documentation page: http://groovy-lang.org/grape.html.

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean autoDownload
      Set to false if you want to disable automatic downloading of locally missing jars.
      boolean disableChecksums
      Set to true if you want to disable checksum checking.
      boolean initContextClassLoader
      Set to true if you want the context classloader to be initialised to the classloader of the current class or script.
      boolean systemClassLoader
      Set to true if you want to use the system classloader when loading the grape.
      String[] systemProperties
      Define any system properties which must be set before invoking the grab - useful for declaring SSL certificates or proxy settings.
    • Element Detail

      • systemClassLoader

        boolean systemClassLoader
        Set to true if you want to use the system classloader when loading the grape. This is normally only required when a core Java class needs to reference the grabbed classes, e.g. for a database driver accessed using DriverManager.
        Default:
        false
      • systemProperties

        String[] systemProperties
        Define any system properties which must be set before invoking the grab - useful for declaring SSL certificates or proxy settings. Currently, this only affects the generated class or script. You may need to also set those same properties for the Groovy compiler. For convenience, a String with comma separated name=value pairs can be used in addition to an array (using Groovy's literal list notation) of String name=value items. The single String shorthand form can't be used if value part of a property contains a comma.
        Since:
        2.4.5
        Default:
        {""}
      • initContextClassLoader

        boolean initContextClassLoader
        Set to true if you want the context classloader to be initialised to the classloader of the current class or script. This is useful for libraries or frameworks that assume that the context classloader has been set. But be careful when using this flag as your script or class might behave differently when called directly (from the command line or from an IDE) versus when called from within a container, e.g. a web container or a JEE container.
        Default:
        false
      • autoDownload

        boolean autoDownload
        Set to false if you want to disable automatic downloading of locally missing jars.
        Default:
        true
      • disableChecksums

        boolean disableChecksums
        Set to true if you want to disable checksum checking.
        Default:
        false