maven编译groovy

发布于 2024-07-25 21:18:46 字数 181 浏览 4 评论 0原文

我遇到的情况是,我的一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我很坚强 2024-08-01 21:18:46

是的,只需使用GMaven。 由于它是一个联合编译器,因此它会自动管理 java 到 groovy 以及 groovy 到 java 的依赖关系。

简而言之,您需要:

  • gmaven-plugin 包含在您的 pom.xml 中;
  • 将您的 groovy 类保存在 src/main/groovysrc/test/groovy 下;
  • 将 gmaven 插件绑定到相关的生命周期阶段。

有关更多详细信息,请参阅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:

  • 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.

旧时模样 2024-08-01 21:18:46

您应该能够通过将 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.

海的爱人是光 2024-08-01 21:18:46

您可以将代码分层,并让较低层调用较高层,但反之则不然。 例如,在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文