从 GNUMake 迁移到 Maven

发布于 2024-09-28 17:31:06 字数 270 浏览 3 评论 0原文

我已经是 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 技术交流群。

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

发布评论

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

评论(2

云雾 2024-10-05 17:31:06

你可以在 Maven 中做任何事情。它通常有一个默认的方式来完成每件事,然后如果你想做一些特殊的事情,你可以挂钩并覆盖。有时需要大量的堆栈溢出和绞尽脑汁才能弄清楚。

甚至还有一个官方的 JFlex Maven 插件

只要有可能,就找一个能用 Maven 插件实现你想要的功能的人。即使它不是 100% 正确,它至少可以让你了解如何让 Maven 做某事。

最小配置

此配置为 src/ 中找到的所有语法文件(.jflex 、 *.jlex 、 *.lex 、 .flex )生成解析器的 java 代码main/jflex/ 及其子目录。生成的Java源代码的名称和包是语法中定义的。生成的 Java 源代码放置在 target/ generated-source/jflex 中,位于遵循 Java 包名称约定的子目录中。
pom.xml

<project>
  <!-- ... -->
  <build>
    <plugins>
      <plugin>
        <groupId>de.jflex</groupId>
        <artifactId>jflex-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <!-- ... -->
  </build>
  <!-- ... -->
</project>

这感觉像是 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

<project>
  <!-- ... -->
  <build>
    <plugins>
      <plugin>
        <groupId>de.jflex</groupId>
        <artifactId>jflex-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <!-- ... -->
  </build>
  <!-- ... -->
</project>

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.

窗影残 2024-10-05 17:31:06

坦白说,我认为你目前的心态更适合 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.

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