File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Does the Groovy compiler also compile Java files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Does the Groovy compiler also compile Java files?" Watch "Does the Groovy compiler also compile Java files?" New topic
Author

Does the Groovy compiler also compile Java files?

Tim Cooke
Rancher

Joined: Mar 28, 2008
Posts: 526
    
  23

Hi Ken,

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?

Many Thanks
Tim

p.s. My colleague has purchased the MEAP version of your book a few months back and he's very complementary about it.


Tim Driven Development
Kenneth A. Kousen
gunslinger & author
Ranch Hand

Joined: Sep 18, 2002
Posts: 89
    
    5
Hi Tim,

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.

Ken


Kenneth A. Kousen, Ph.D. (assorted certs), President, Kousen IT, Inc.
Author of Making Java Groovy - http://www.kousenit.com
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1477
    
  11

@Tim:

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.


No more Blub for me, thank you, Vicar.
Tim Cooke
Rancher

Joined: Mar 28, 2008
Posts: 526
    
  23

Ken: That was very much the response I was hoping for. Thanks very much. I will be talking with my team very soon about introducing Groovy and Spock into our testing framework. To ease the testing effort will smooth the way for folks to pick up TDD practices easier and earlier.

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!
Kenneth A. Kousen
gunslinger & author
Ranch Hand

Joined: Sep 18, 2002
Posts: 89
    
    5
Just FYI, the slides for my typical Spock presentation are at slideshare.net, at Spock Friendly Testing. I also have a presentation with a similar name online at InfoQ (http://www.infoq.com).

Good luck,

Ken
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Tim Cooke wrote:I am very keen to introduce Spock for our developer testing


Tim,
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

Burk


SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
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.


Ken,
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.

Burk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does the Groovy compiler also compile Java files?
 
Similar Threads
Greasing the wheels of Java - What's up with all the hype on Ruby and Groovy?
Grails: A Quick Start Guide Question
Is Groovy production ready?
Making Java Groovy: Test coverage for Groovy?
Benefits of Learning Clojure?