0
@Grapes([
    @Grab("org.codehaus.geb:geb-core:0.7.2"),
    @Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.15.0"),
    @Grab("org.seleniumhq.selenium:selenium-support:2.15.0")
])
import geb.Browser

Browser.drive {
  // Load the page
  go "http://www.whu.edu.cn"

  // $("a") returns all hyperlinks on the page, similar to jQuery
  $("a").each { a ->
     // Display the required link properties and attributes
     println """
        The link to '${a.@href}' with text '${a.text()}' is at location (${a.x}, ${a.y}),
        with a height of ${a.height}px and a width of ${a.width}px.
     """
  }
}

I just created my first Groovy project in Eclipse and created my first Groovy class inside the project. Everything written for the class is as above. When I ran the script, it didn't throw any error nor would it terminate in time.

Was it trying to download all the annotated dependencies? If so, does it need to download the dependencies each time it is run? Or it is once and for all?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Terry Li
  • 16,870
  • 30
  • 89
  • 134

1 Answers1

2

When you run this, it will check to see if the correct version of each of the libraries annotated with @Grab has been downloaded, and if not, will attempt to download it. And it's not just the named libraries, it's also those libraries' dependencies.

So, yes, it can take some time to run this the first time. Subsequent runs should take much less time.

Note that this is just a convenience. You can also download the required libraries, and specify them in the -classpath argument to the 'groovy' command (and remove the Grapes/Grab construct).

For more info, see http://groovy.codehaus.org/Grape

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • By the way, which directory are they downloaded to? I also wonder if there's a way to keep track of the downloading process. – Terry Li Dec 14 '12 at 04:40
  • by default, it's .groovy/grape in your home directory, so ~/.groovy/grape on Linux / OS X. If you're on Windows, then I'm not sure of the location of .groovy - it probably depends on the version of Windows, and your guess is as good as mine. – GreyBeardedGeek Dec 14 '12 at 04:44