预处理源代码作为maven构建的一部分 [英] Preprocessing source code as a part of a maven build

查看:176
本文介绍了预处理源代码作为maven构建的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多需要自定义预处理的Java源代码。我想摆脱它,但现在不可行,所以我坚持下去。鉴于我有一个不应该存在的不幸问题,我如何使用maven解决它?

I have a lot of Java source code that requires custom pre-processing. I'd like rid of it but that's not feasible right now so I'm stuck with it. Given that I have an unfortunate problem that shouldn't have existed in the first place, how do I solve it using maven?

(总的来说,我正在用一个基于python的构建系统替换一个基于python的构建系统,所以请一次改进一次。修复非标准源代码代码更难,稍后会出现。)

(For the full story, I'm replacing a python-based build system with a maven one, so one improvement at a time please. Fixing the non-standard source code is harder, and will come later.)

是否可以使用任何现有的Maven插件在编译期间实际更改源文件? (显然只留下原始的,未处理的代码)

Is it possible using any existing Maven plugins to actually alter the source files during compile time? (Obviously leaving the original, unprocessed code alone)

要清楚,通过预处理我的意思是预处理和天线一样,或者C编译器会预处理代码,根据自定义,我的意思是它完全是专有的,看起来一点也不像C或天线预处理。

To be clear, by preprocessing I mean preprocessing in the same sense as antenna or a C compiler would preprocess the code, and by custom I mean that it's completely proprietary and looks nothing at all like C or antenna preprocessing.

推荐答案

这是非常的东西可行的,我过去做过非常相似的事情。

This is something that is very doable and I've done something very similar in the past.

我的一个项目的一个例子,我使用antrun插件来执行外部程序流程来源:

An example from a project of mine, where I used the antrun plug-in to execute an external program to process sources:

  <build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <executions>
        <execution>
          <id>process-sources</id>
          <phase>process-sources</phase>
          <configuration>
            <tasks>
               <!-- Put the code to run the program here -->
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

请注意我指示运行此阶段的标记。 Maven中生命周期的文档是此处。另一个选择是实际编写自己的Maven插件来执行此操作。它有点复杂,但也很可行。您仍将按照我在此处记录的内容进行配置。

Note the tag where I indicate the phase where this is run. Documentation for the lifecycles in Maven is here. Another option is to actually write your own Maven plug-in that does this. It's a little more complex, but is also doable. You will still configure it similarly to what I have documented here.

这篇关于预处理源代码作为maven构建的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆