Documentation

Groovy

Groovy is the default scripting language in bemoko.

Grape

Grape provides the ability for a Groovy script to dynamically download dependent libraries based on the @Grab annotations, e.g.

<source lang="groovy">
@Grab(group='commons-primitives', module='commons-primitives', version='1.0')
</source>

The following system properties drive the configuration of grape:

System Property NameDefault ValueDescription
groovy.rootdefaults to ".groovy" directory in the system property user.home directory, e.g. /home/bemoko/.groovyLocation of groovy configuration files including grape configuration files
groovy.grape.enabletrueEnable grape
groovy.grape.autoDownloadtrueEnable auto download

Configuring Ivy Repository

Grape downloads dependencies into the ~/.groovy/grapes directory. You can configure the grape repository in the ~/.groovy/grapeConfig.xml file

Deploying graped repository onto another system without dynamic download

Sometimes, e.g. deployment into production, you may want to take the jars that were "grabbed" and deploy them into another system. To do this, start with an empty grape repository, run your site or sites that trigger the grab.

Then tar up the grape repository

tar cvf grapes.tar ~/.groovy/grapes

and copy across to you other system into the groovy home directory. For example if you have the groovy home configured on the JVM as -Dgroovy.root=/opt/local/bemoko/groovy then unpack the grapes.tar into the /opt/local/bemoko/groovy such that the grapes repository is located at /opt/local/bemoko/groovy/grapes.

Troubleshooting grapes

If you see the an exception such as the following:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, 
General error during conversion: Error grabbing Grapes -- [download failed: 
xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]
java.lang.RuntimeException: Error grabbing Grapes -- 
[download failed: xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]

Then it may be because some dependencies can not be loaded. It can be easier to troubleshoot this by explicitly installing the dependency with grape on the command line. Note that grape comes with a Groovy=installation.

When you have Groovy installed, you can then install the required dependency with the command line as follows:

grape -V resolve net.sourceforge.htmlunit htmlunit 2.5
Make sure that the grape command line installs the dependencies in the same groovy root directory as your bemoko is using. bemoko will use the use either (1) the .groovy directory in the system property user.home directory, e.g. /home/bemoko/.groovy or (2) or the system property groovy.root directory, e.g. groovy.root=/Users/bemoko/.groovy. The value of user.home is output as a bemoko INFO message in the logs at startup, e.g. "System : user.home=/Users/bemoko". The command line groovy directory is the .groovy directory in your home directory.

If the default Grapes is struggling with dependancies then you may need to set up a new repository, an example of the required xml is below:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
    <chain name="downloadGrapes">
      <filesystem name="cachedGrapes">
        <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
        <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
      </filesystem>
      <!-- todo add 'endorsed groovy extensions' resolver here -->
      <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/>
      <ibiblio name="ibiblio" m2compatible="true"/>
      <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/>
      <ibiblio name="mvnrepository" root="http://mvnrepository.com/" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

.


More