June 2021
« Sep    
Your widget title

Posts Tagged ‘Groovy’

PostHeaderIcon How to compile both Java classes and Groovy scripts with Maven?


Your project includes both Java classes and Groovy scripts. You would like to build all of them at the same time with Maven: this must be possible, because, after all, Groovy scripts are run on a Java Virtual Machine.


In your pom.xml, configure the maven-compiler-plugin as follows:


With such setup, default compiler (which cannot compile Groovy scripts parallelly of Java sources) will be replaced with Eclipse’s one (which can).

PostHeaderIcon (long tweet) Error injecting: org.codehaus.groovy.eclipse.compiler.GroovyEclipseCompiler


On building a Groovy project with Maven, I got the following error:

Error injecting: org.codehaus.groovy.eclipse.compiler.GroovyEclipseCompiler
java.lang.NoClassDefFoundError: org/codehaus/plexus/compiler/CompilerResult

Quick fix

Downgrade maven-compiler-plugin to version 3.0 instead of branch 2.3.X.

PostHeaderIcon How to call external shell in Groovy?

Going on learning Groovy, I faced the following case: how to call an external shell (or MS-DOS) command from a Groovy script?

It is very easy. The following example show how to display the Subversion status of the current folder:

def proc = &quot;svn st&quot;
def sb = new StringBuffer()

println proc.text + &quot;\n&quot; +  sb.toString()

PostHeaderIcon Error grabbing Grapes — [unresolved dependency:; not found]

I have learnt Groovy since the beginning of the week.
I had to import some classes from Oracle JDBC driver. As a newbie, I wrote the following annotation:

@Grab(group = '', module = 'ojdbc14', version = '')

I got the following error:

Error grabbing Grapes -- [unresolved dependency:; not found]

To sum up, adding a dependency to Oracle driver raises two issues:

  • adding any external dependency
  • adding a dependency to any JDBC driver

Indeed, Grab requires a kind of Maven repository, and you can catch the link between the @Grab annotation below and classic Maven 2 <dependency> tag. As I understood, Grab instructions are closer to Ivy than to Maven system. In my situation, having no “Grab repo” (I don’t know how to call that), I had to download the jars from a Maven repo. To fix it, two operations are needed: hint at Maven (or Ivy) repo, and allow Groovy to access the network.

Regarding the second issue, it is answered by added a @GrabConfig annotation.
Therefore, to fix the original issue:

  • replace
    @Grab(group = '', module = 'ojdbc14', version = '')


    @GrabResolver(name='nameOfYourMavenRepo, root='http://url-of-your-maven-repo:port')
    @Grab(group = '', module = 'ojdbc14', version = '')
  • at first run, if needed, hint at the proxy to allow Grab to download the Jars, eg:
    groovy -Dhttp.proxyHost=myProxyHost -Dhttp.proxyPort=8080

You may notice the needed JAR will be written in the $USER_HOME/.groovy/grapes folder.

PostHeaderIcon Filter too large files in Mule ESB


You use a filter connector in Mule ESB 2.2.1, to perform any operation (let’s say: to send them on JMS, but this does not matter). You would like to filter files owing to their size, ie stop the handling of files larger than 10,000,000 bytes for instance.

We assume the files you handle are text files (not binary).


In your Mule XML config file, add the following block, using a short Groovy script:

<message-properties-transformer name="add-properties">
     <add-message-property key="fileSizeOK"
             value="#1" />

In the tag <file:inbound-endpoint>, add the attribute: transformer-refs="add-properties"
Now, add a tag <message-property-filter pattern="fileSizeOK=true"/>. Your outbound should then be similar to:

                    <jms:outbound-endpoint queue="lalou.jonathan.jms.queue"
                    <message-property-filter pattern="fileSizeOK=true"/>
                    <file:outbound-endpoint path="/my/folder/"
                        connector-ref="fileConnector" outputPattern="error/#[header:originalFilename].too_big.#[function:dateStamp:yyyyMMdd_HHmmss_SSSSS].KO" />

Many thanks to Vincent N. for his help.