Create your own groovy library

Does anyone have an idea what is the best way to create your own library for groovy.

I have several methods that I just don't want to copy and paste into all my groovy scripts.

The ideal solution is to do this with

import myownmethods 

How to create myownmethods.jar library?

Thanks for any answer and solution.

Greetings

+6
source share
2 answers

The easiest way is to compile your groovy files with groovyc and then pack them into a jar file with jar . For instance:

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

I will also consider gradle. To get started, you can use build.gradle containing only:

 apply plugin: 'groovy' 

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

+9
source

You must follow the same process as for the Java library, i.e.

  • Create a project for code
  • Set up your favorite build tool (Ant, Maven, etc.) to create a JAR for this project
  • Place the JAR somewhere where other projects can find. If you use a tool like Ivy or Maven that does dependency management, most likely you will want to deploy it to the repository. Otherwise, you can probably just put it somewhere in the original control †
  • Projects that depend on this library must either download them from the repository (when using dependency management), or copy it to the lib directory (if not) †

† I know this sucks, but I don’t remember how I used dependency management without using the dependency management tool

+2
source

Source: https://habr.com/ru/post/901728/


All Articles