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 Name | Default Value | Description |
|---|---|---|
| groovy.root | defaults to ".groovy" directory in the system property user.home directory, e.g. /home/bemoko/.groovy | Location of groovy configuration files including grape configuration files |
| groovy.grape.enable | true | Enable grape |
| groovy.grape.autoDownload | true | Enable 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
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>
.