I have a situation where some of my groovy code references my java files, but I also have different java files that reference the same groovy code. When trying to compile in maven, I either need to compile the groovy before or after the java, and that won't really work since the groovy code depends on some java files, and different java files depend on the groovy code. Is there a way to handle this sort of dependency?
You can partition your code in layers and have lower layers call upper layers but never vice versa. For example, in a Web app you can have a view layer, a service layer, and a persistence layer. The view layer calls the service layer and the service layer calls the persistence layer, but the persistence layer will never call the service layer or the view layer. If you want groovy/java code to exist in the same layer then make sure one calls the other but they don't both call each other. The bottom line is that you should avoid bi-directional dependencies.
Yes, just use GMaven. Since it's a joint compiler, it automatically manages your java to groovy and groovy to java dependencies.
Briefly, you will need to:
- include the
gmaven-plugin
in yourpom.xml
; - keep your groovy classes under
src/main/groovy
orsrc/test/groovy
; - bind the gmaven plugin to the relevant lifecycle phases.
For more details see building groovy projects.