maven compile groovy
Asked Answered
P

3

12

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?

Provocation answered 20/6, 2009 at 21:13 Comment(0)
J
8

You should be able to compile your code by adding the gmaven plugin to your maven pom.xml. It generates Java stubs of your groovy code to deal with the type of inter-language referencing you're dealing with. I use it quite a bit and it works very well.

Jaqitsch answered 20/6, 2009 at 21:28 Comment(0)
P
11

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 your pom.xml;
  • keep your groovy classes under src/main/groovy or src/test/groovy;
  • bind the gmaven plugin to the relevant lifecycle phases.

For more details see chapter Maven Integration on the groovy homepage.

Presence answered 20/6, 2009 at 21:27 Comment(0)
J
8

You should be able to compile your code by adding the gmaven plugin to your maven pom.xml. It generates Java stubs of your groovy code to deal with the type of inter-language referencing you're dealing with. I use it quite a bit and it works very well.

Jaqitsch answered 20/6, 2009 at 21:28 Comment(0)
C
0

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.

Cabe answered 20/6, 2009 at 21:23 Comment(1)
That's true but having bi-directional dependencies can lead to unnecessarily complex and less maintainable code. In the context of this question I agree that using GMaven is the right answer but I would still refactor the code to eliminate, or at least reduce the bi-directional relationships.Cabe

© 2022 - 2024 — McMap. All rights reserved.