Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Grape in scripts with multiple files

Tags:

groovy

I'd like to use @Grape in my groovy program but my program consists of several files. The examples on the Groovy Grape page all seem to assume that your script will consist of one file. How can I do this? Should I just add it to one of the files and expect that the imports will work from the others? If so, then is it common to place all the @Grape calls in one file with no other code? Do I need to add the Grape call to all files that will import the package? Do I need to download the JAR and create a Gradle file, which I was getting away without at this point?

like image 417
dromodel Avatar asked Oct 12 '22 01:10

dromodel


1 Answers

the grape engine and the @grab annotation were created as part of core groovy with single file scripts in mind, to allow a chunk of text to easily become a fully functional program.

for larger applications, gradle is an awesome build tool with lots of useful features.

but yes, you can manage all the application dependencies just with grape.
whether you annotate every file or a single one does not matter, just make sure the @grab annotated file is read before you try to use the external class.
annotating the main class is probably better as you will easily lose track of library versions if you have the annotations scattered.

and yes, you should consider gradle for any application with more than a dozen files or anything you might want to reuse elsewhere as a library.

like image 171
jpertino Avatar answered Oct 18 '22 02:10

jpertino