This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven: Define different compiler for src/main and src/test code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven: Define different compiler for src/main and src/test code" Watch "Maven: Define different compiler for src/main and src/test code" New topic
Author

Maven: Define different compiler for src/main and src/test code

Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 835
    
  39

Howdy Ranchers,

Is it possible in Maven (v3.0.3) to define a different compiler for code under src/test and for code under src/main? My motivation for wanting to do this is that I would like to start using the Spock framework for my developer testing, which requires Groovy, but do not want to use the Groovy compiler for the production code. At present I am unsure whether my company will allow production code to be compiled with anything other than javac.

So I'd like to tell Maven to use the Java compiler for src/main code and use the Groovy compiler for src/test code. Is this possible?


Tim Driven Development
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2273
    
  28

If you drop the groovy compiler plugin into your Pom, the groovy compiler plugin will compile groovy files, and maven compiler plugin will compile java files. All you need to do is make sure all your production code is in src/main/java and all your groovy test code is in src/test/groovy. Groovy compiler will compile files in src/test/groovy, and since it is a test folder the classes compiled by groovy won't go into production
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 835
    
  39

Which groovy compiler plugin are you referring to? From what I can see of the documentation in order to include the Groovy compiler you have to reconfigure the maven-compiler-plugin plugin. This I imagine would then just replace the Java compiler completely causing all code to be compiled with the Groovy compiler.

How would I drop the Groovy compiler plugin into my pom as an additional compiler definition?
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 835
    
  39

I had an interesting conversation with an old colleague of mine on this topic. He thinks that the Groovy compiler just converts the Groovy code into Java code which is then given to the Java compiler to be turned into bytecode as normal.

Can anybody either confirm or debunk this idea?
 
jQuery in Action, 2nd edition
 
subject: Maven: Define different compiler for src/main and src/test code
 
Similar Threads
Branch for Testing?
Maven Testa as standalone (jar) application
Unit Testing with Groovy?
Where to place Selenium tests in separate maven project
Property files for different environments