Showing posts with label Groovy. Show all posts
Showing posts with label Groovy. Show all posts

Thursday, February 23, 2012

Modify grapeConfig.xml to speed up groovy script with @Grab

I had a post on speed up groovy script startup time if Grape @Grab annotation is used in the script.
The cause is described in this post, http://swainya.blogspot.com/2011/09/skip-download-when-groovy-code.html.

The solution described in that post is to add one line in the .groovy/grapeConfig.xml to decrease cache TTL.  Add

<property name="ivy.cache.ttl.default" value="15m"/>

in the <ivysettings> section.

Your grapeConfig.xml will look like this after adding that line


<ivysettings>
  <property name="ivy.cache.ttl.default" value="15m"/>
  <settings defaultResolver="downloadGrapes"/>
......

Friday, September 30, 2011

Find directory path of the current groovy script

Bash or PHP script has a function that returns the directory path of the current script file.

$my_dir=dirname(__FILE__);

Groovy script lacks such a capability but an alternative is available by calling

def my_dir = new File(getClass().protectionDomain.codeSource.location.path).parent

Tuesday, September 27, 2011

Skip download when groovy code annotated with Grapes

Grapes is a great utility to manage class path automation when coding with groovy.
http://groovy.codehaus.org/Grape
But it slows down the start-up if there are a lot of dependent jars to download.  Even all the dependent jar files have been downloaded to local m2 and grapes store previously, the download process still takes place, which slow things down unnecessarily.

Use the following options to ask groovy look into local storage directly.
groovy -Dgroovy.grape.autoDownload=false [groovy file path] [arguments ......]