从 GNUMake 迁移到 Maven
我已经是 Make 构建系统的长期用户,但我决定开始学习 Maven 构建系统。虽然我已经阅读了大部分在线文档,但似乎没有一个文档能够提供我正在寻找的类比。我了解系统的生命周期,但我没有看到任何有关编译步骤依赖项的参考。例如,我想生成 JFlex 语法作为编译生命周期步骤的一部分。目前,我认为没有办法使该步骤成为预编译阶段步骤。文档似乎对此有所限制。一般来说,步骤依赖关系的概念似乎已融入 Maven 中,并且需要插件才能进行任何更改。是这样吗?我缺少什么,因为目前 Maven 构建系统似乎在如何设置编译步骤方面非常有限。
I've been a long time user of the Make build system, but I have decided to begin learning the Maven build system. While I've read through most of the online docs, none seem to give me the analogies I'm looking for. I understand the system's lifecycle, but I have not see one reference to compile step dependencies. For example, I want to generate a JFlex grammar as part of the compile lifecycle step. Currently, I see no way of making that step a pre-compile phase step. Documentation seems to be limited on this. In general, the concept of step dependencies seem to be baked into Maven and require a plugin for any alteration. Is this the case? What am I missing, because currently the Maven build system seems very limited in how you can setup compilation steps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以在 Maven 中做任何事情。它通常有一个默认的方式来完成每件事,然后如果你想做一些特殊的事情,你可以挂钩并覆盖。有时需要大量的堆栈溢出和绞尽脑汁才能弄清楚。
甚至还有一个官方的 JFlex Maven 插件。
只要有可能,就找一个能用 Maven 插件实现你想要的功能的人。即使它不是 100% 正确,它至少可以让你了解如何让 Maven 做某事。
最小配置
此配置为 src/ 中找到的所有语法文件(.jflex 、 *.jlex 、 *.lex 、 .flex )生成解析器的 java 代码main/jflex/ 及其子目录。生成的Java源代码的名称和包是语法中定义的。生成的 Java 源代码放置在 target/ generated-source/jflex 中,位于遵循 Java 包名称约定的子目录中。
pom.xml
这感觉像是 Maven 的做事方式。将您的内容放在正确的文件夹(src/main/flex)中,该插件将自动将其构建到您的项目中。如果你想做更奇特的自定义东西,有一些选项 。但 Maven 的重点是约定优于配置。
You can do anything in Maven. It generally has a default way to do each thing, and then you can hook in and override if you want to do something special. Sometimes it takes a lot of Stack Overflowing and head scratching to figure it out.
There is even an official JFlex Maven plugin.
Whenever possible, find someone who has made a Maven plugin do what you want. Even if it isn't 100% right, it may at least give you an idea on how to make maven do something.
Minimal configuration
This configuration generates java code of a parser for all grammar files (.jflex , *.jlex , *.lex , .flex ) found in src/main/jflex/ and its sub-directories. The name and package of the generated Java source code are the ones defined in the grammar. The generated Java source code is placed in target/generated-source/jflex , in sub-directories following the Java convention on package names.
pom.xml
This feels like the maven way to do things. Put your stuff in the right folders (src/main/flex), and this plugin will automatically build it into your project. If you want to do fancier custom stuff, there are some options. but Maven is all about favoring convention over configuration.
坦白说,我认为你目前的心态更适合 ant,而不是 Maven,我建议从它开始。
To be frank I think that your current mindset maps much better to ant than to maven, and I would suggest starting with that.