Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating own groovy library

Tags:

jar

groovy

Do anyone have an idea whats the best way of creating an own library for groovy.

I have several methods which i just dont want copy and paste into all my groovy scripts.

The perfect solution would be to do it by an

import myownmethods

How to create the library myownmethods.jar?

Thanks for any answer and solution

Cheers

like image 677
Booyeoo Avatar asked Nov 17 '11 16:11

Booyeoo


2 Answers

The simplest method is to compile your groovy files with groovyc and then package them into a jar file with jar. For example:

groovyc -d classes myclasses.groovy
jar cvf myclasses.jar -C classes .

I'd also consider looking at gradle. To get started, you can use a build.gradle containing just:

apply plugin: 'groovy'

Then put your source files in a subdirectory called src/main/groovy and run gradle jar. It will build your source files into a jar file in build/libs.

like image 157
ataylor Avatar answered Sep 20 '22 09:09

ataylor


You should follow the same process that you would for a Java library, i.e.

  • Create a project for the code
  • Configure your favorite build tool (Ant, Maven, etc.) to build a JAR for that project
  • Put the JAR somewhere where other projects can find it. If you're using a tool like Ivy or Maven that does dependency management you'll likely want to deploy it to a repository. Otherwise, you can probably just put it somewhere in source control †
  • Projects that depend on this library should either load it from the repository (if using dependency management), or have it copied into their lib directory (if not) †

† I know this sucks, but I can't remember how I used to manage dependencies without using a dependency management tool

like image 36
Dónal Avatar answered Sep 20 '22 09:09

Dónal