Details
Description
Try this in Groovy Console:
@Grapes( [@Grab(group='org.spockframework', module='spock-core', version='0.2'), @Grab(group="junit", module="junit", version="4.7")]) class HelloSpock extends Specification { def "can you figure out what I'm up to?"() { expect: name.size() == length where: name << ["Kirk", "Spock", "Scotty"] length << [4, 5, 6] } }
Output:
1 compilation error: unable to resolve class Specification at line: 1, column: 1
This means that Spock is not on the compile class path. When I @Grab JUnit and Spock individually by introducing a fake class, script works as expected. (Well, not quite. I need to add JUnitCore.run(HelloSpock) because otherwise, the test class is no longer found.)
By the way, if Ivy was fully compatible with Maven, the JUnit @Grab wouldn't be necessary, because JUnit is a mandatory compile-time dependency of Spock. Admittedly, Ivy's transitive dependency resolution is more correct than Maven's, but at the cost of breaking compatibility. Is there a way to tweak this?
Issue Links
- is related to
-
GROOVY-3861
AST transforms of spock do not take effect when the library is loaded using @Grab
-
I don't think that the compilation error you are getting here is due to any Grape bug. Your script should be like:
Since spock.lang.* package is not a default import into groovy, you need to tell in the script which package class Specification could be found in.
Also, looking at the grape executing your script, I noticed that it was retrieving junit-4.6 correctly as the dependency, so you should not need @Grab JUnit.
Can you first try with the spock.lang.Specification and then without the Junit @Grab?