Search code examples
javaspring-bootgroovy

How to chose both Java and Groovy?


When you create a Spring Boot app via the Spring Initializr (which is the only way I know), you have to chose either Java or Groovy. This seems odd, as Groovy is just a superset of Java.

Anyway, I want to use both!

How does one have both Java and Groovy, like you can do seamlessly with Grails?


Solution

  • Pick Groovy and then put your .java files inside the Groovy source root; the Groovy compiler falls back to the Java compiler for those files. Doing it this way, you make sure, that dependencies are handled correctly (if you put them inside the Java source root, one of the source roots will be compiled first and you will have a hard time handling dependencies properly).