maven编译groovy
我遇到的情况是,我的一些 groovy 代码引用了我的 java 文件,但我也有不同的 java 文件引用相同的 groovy 代码。 当尝试在maven中编译时,我需要在java之前或之后编译groovy,这不会真正起作用,因为groovy代码依赖于一些java文件,而不同的java文件依赖于groovy代码。 有没有办法处理这种依赖关系?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,只需使用GMaven。 由于它是一个联合编译器,因此它会自动管理 java 到 groovy 以及 groovy 到 java 的依赖关系。
简而言之,您需要:
gmaven-plugin
包含在您的pom.xml
中;src/main/groovy
或src/test/groovy
下;有关更多详细信息,请参阅Maven 集成一章绝妙的主页。
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:
gmaven-plugin
in yourpom.xml
;src/main/groovy
orsrc/test/groovy
;For more details see chapter Maven Integration on the groovy homepage.
您应该能够通过将 gmaven 插件添加到您的 maven pom.xml 来编译您的代码。 它生成 groovy 代码的 Java 存根,以处理您正在处理的语言间引用类型。 我经常使用它并且效果很好。
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.
您可以将代码分层,并让较低层调用较高层,但反之则不然。 例如,在 Web 应用程序中,您可以拥有视图层、服务层和持久层。 视图层调用服务层,服务层调用持久层,但是持久层永远不会调用服务层或视图层。 如果您希望 groovy/java 代码存在于同一层中,请确保一个调用另一个,但它们不会互相调用。 最重要的是,您应该避免双向依赖。
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.