aspose file tools*
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
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: 1001
    
  47

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: 2370
    
  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: 1001
    
  47

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: 1001
    
  47

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven: Define different compiler for src/main and src/test code