0

I am quite new to groovy and need to clarify on the Groovy Dependency management.

Here is the summary according to my "Homework":

  • Groovy Dependency management is as simple as adding an annotation to the script. E.g.
    @Grab('org.springframework:spring-orm:3.2.5.RELEASE')
  • Grape will then quickly add the dependencies from maven repository to your classpath

So, is adding to my groovy script the dependency annotation is all that I need, and Groovy/Grape will take care of the rest, when I run my Groovy script, right? (or there are some prerequisites, like I can't put my groovy script randomly anywhere, but has to be at a specific place like within a Groovy project, etc)

Second question, how to translate Maven dependency to Groovy/Grape dependency annotation?

For e..g., this is the Maven dependency for Opencsv:

<dependencies>
    <dependency>
        <groupId>com.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>5.2</version>
    </dependency>
</dependencies>

Does that translate to @Grab('com.opencsv:opencsv:5.2')?

Third question,

suppose I need to import org.apache.commons.collections.primitives.ArrayIntList, how can I come up with a Groovy/Grape dependency annotation as

@Grab(group='commons-primitives', module='commons-primitives', version='1.0')

I.e., where can I found the connection between org.apache.commons.collections.primitives.ArrayIntList and commons-primitives?

And finally,

where would Groovy/Grape store the downloaded .jar files?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
xpt
  • 20,363
  • 37
  • 127
  • 216
  • 1
    this site contains dependency declaration for different languages including Grape/Grab: https://mvnrepository.com/artifact/com.opencsv/opencsv/5.2 – daggett Dec 04 '20 at 14:10
  • 1
    Central https://search.maven.org/artifact/com.opencsv/opencsv/5.3/jar. has that also see on the right side... – khmarbaise Dec 04 '20 at 14:12
  • 1
    and yes, you can put your script anywhere, and run it with `groovy path/scriptName.groovy`. if you need local dependencies then use `-cp` to set classpath – daggett Dec 04 '20 at 14:19
  • and for the last question `@Grab(group='commons-primitives', module='commons-primitives', version='1.0')` is equivalent to `@Grab('commons-primitives:commons-primitives:1.0')`, the latter is just shorter. – Matias Bjarland Dec 04 '20 at 15:08
  • You have four reasonable questions here, which is about three too many for a Stack Overflow post. I'm going to vote to close this, though I think any or all of these would be fair individual posts. – M. Justin Apr 13 '22 at 04:02

0 Answers0