2

I have the following groovy dependency declared:

@GrabResolver(name='mymirror', root='http://myartifactory/public/')
@Grab(group='groupid', module='artifactid', version='1.2.3')
println //What should I write here to see: c:\Users....m2....artifactid.jar

How can I get the location of the downloaded resolved artifact in groovy?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113

2 Answers2

2
@Grab(group='net.sourceforge.plantuml', module='plantuml', version='8049')
import groovy.grape.Grape

def grape = Grape.getInstance()
def r = grape.listDependencies(this.getClass().getClassLoader())
println r
println grape.resolve(r[0])

prints

[[group:net.sourceforge.plantuml, module:plantuml, version:8049]]
[file:/C:/Users/dm/.groovy/grapes/net.sourceforge.plantuml/plantuml/jars/plantuml-8049.jar]
daggett
  • 26,404
  • 3
  • 40
  • 56
1

By default, Grape stores a cache of the jars on ~/.groovy/grapes. So, I think you can do something like this:

@GrabResolver(name='mymirror', root='http://myartifactory/public/')
@Grab(group='groupid', module='artifactid', version='1.2.3')

String grapeCacheDir = "${System.getProperty('user.home')}/.groovy/grapes"
String group = 'groupid'
String module = 'artifactid'
String version = '1.2.3'

File myJar = new File("$grapeCacheDir/$group/$module/jars/${module}-${version}.jar")
println myJar.path

It's not a preety solution, but I can't think in any other options.

Edumelzer
  • 1,066
  • 1
  • 11
  • 22