Groovy 1.6 has a very cool new feature: Grape - The Groovy Adaptable Packaging Engine
Example:
import org.mortbay.jetty.Server import org.mortbay.jetty.servlet.* import groovy.servlet.* @Grab(group = 'org.mortbay.jetty', module = 'jetty-embedded', version = '6.1.0') def runServer(duration) { def server = new Server(8080) def context = new Context(server, "/", Context.SESSIONS); context.resourceBase = "." context.addServlet(TemplateServlet, "*.gsp") server.start() sleep duration server.stop() } runServer(10000)
The @Grab annotation will resolve and download the embeddable jetty servlet container and all its dependencies ... just as we are used to by good old Maven, just without all the pom-hassle!
Place a simple hello.gsp in the same directory, and access it at http://localhost:8080/hello.gsp ...
Very cool, isn't it?
On second thought though we should not overestimate the feature. For one thing it exposes the known weaknesses of Maven (accessibility to needed repositories, availability of all dependencies ...).
On top of that it shifts these problems from build-time (Maven) to run-time (Grape). This can be problemetic since resolving and downloading dependencies can be quite an overhead, that is not always desirable at runtime. And the fact that Grape is not giving any feedback, what is going on (at least not per default) does not improve the situation ...
Considering this, I think Grape is a cool feature for developing and exchanging simple apps/scripts and for prototyping ... but I would not consider it for a productive app.
No comments:
Post a Comment