I posted this question over here a couple of weeks ago and didn't get much traction with it (probably didn't ask it very well). If I have a project with a mix of Java and Groovy code in it, does the Groovy compiler compile all code or does the Groovy compiler only compile the Groovy code and let the JDK compile the Java code?
At work we have a purely Java application and I am very keen to introduce Spock for our developer testing but as far as I'm aware the company might be a little tetchy about having their production Java code compiled in anything but the prescribed JDK. If I can be sure that the Groovy compiler will only get involved with the Groovy code in the test package and leave the production Java code for the JDK then I'm golden.
Do you know how this works?
p.s. My colleague has purchased the MEAP version of your book a few months back and he's very complementary about it.
The Groovy compiler uses whatever JDK is currently installed during the compilation process, but it is a true cross-compiler. You can use the "groovyc" command to compile both Groovy and Java, but ultimately it's using the the JDK you have. I'm not sure how the details work under the hood, but the effect is the same. It's not going to interfere with the Java compilation.
If you need additional information, that might be a good question to ask on the Groovy users and/or developer email lists. Those can be found at http://groovy.codehaus.org/Mailing+Lists . I seriously doubt you'll have any problems, though.
In fact, adding Groovy tests to existing Java projects is a great way to introduce Groovy to an organization, because you're not changing any deployed production code.
Please thank your colleague for me, btw.
As well as Ken's book, you might also want to get hold of The Well-Grounded Java Developer which is an excellent book and has a lot of stuff on polyglot progamming on the JBM, including hwo to mix Java with Groovy/Clojure/Scala.
Chris: I just had a quick scan through the sample pages on Amazon for The Well Grounded Java Developer and it certainly does look like a valuable read. I learnt that there is such a thing as a "TimSort"! Now that sounds like the very thing for me!
Tim Cooke wrote:I am very keen to introduce Spock for our developer testing
One of the sample chapters on the Manning site is Chapter 6, titled, "Testing Groovy and Java projects" - it should be right up your alley. Section 6.4 (page 156) is a nice introduction to Spock. Here's the link: http://www.manning-source.com/books/kousen/sample_ch06_MJG.pdf
Kenneth A. Kousen wrote:In fact, adding Groovy tests to existing Java projects is a great way to introduce Groovy to an organization, because you're not changing any deployed production code.
I totally agree with that approach for two reasons:
1) Using Spock for automated tests makes writing the tests easier and more fun/interesting since you're working with a new (but familiar) language,
2) You don't have to worry about not being as skilled with Groovy since you're 'just' writing tests, so there's less pressure than there would be if you were writing code destined for production.
And, of course, there's Secret Reason Three: Developers who woulndn't otherwise do so might start writing automated tests.