简体   繁体   English

参数化Maven多模块构建

[英]Parameterise a Maven Multimodule Build

I'm looking for a possibility to parameterise a multi-module build in a way that I can replace/specify some files (eg UML files) that are used during the build in order to produce different output. 我正在寻找一种可能的方式来参数化多模块构建,我可以替换/指定在构建期间使用的一些文件(例如UML文件)以产生不同的输出。 The procedure of the build stays the same but I want to be able to produce different output depending on the input UML model. 构建过程保持不变,但我希望能够根据输入的UML模型生成不同的输出。

I have a multi-module project that builds several jars based upon an UML model. 我有一个多模块项目,可以根据UML模型构建几个jar。 The pom structure looks as follows: pom结构如下:

+ generation
  - mod1
  - mod2
  - mod3

The root pom (generation) generates java sourcecode (.java) based upon an UML model stored in the directory /uml. 根pom(generation)基于存储在目录/ uml中的UML模型生成java源代码(.java)。 Afterwards the modules (mod1...3) compile distinct subsets of this sourcecode and package the output as jar. 之后,模块(mod1 ... 3)编译此源代码的不同子集,并将输出打包为jar。

I want to reuse this build procedure and apply it to different UML models. 我想重用这个构建过程并将其应用于不同的UML模型。 How can I reuse the entire generation, compilation and packaging procedure defined in the multimodule project in other maven projects? 如何在其他maven项目中重用多模块项目中定义的整个生成,编译和打包过程?

# Generate jars based upon the foo UML model
+ generation-foo
  /uml/foo.uml

# Generate jars based upon the bar UML model
+ generation-bar
  /uml/bar.uml

Update 更新
I could use profiles in the generation project in order to define the different input uml models and then just activate the relevant one. 我可以在生成项目中使用配置文件来定义不同的输入uml模型,然后激活相关的模型。 But I would lose traceability that way. 但是我会以这种方式失去可追溯性。

Perhaps a completely new approach would be a better idea ... any suggestions? 也许一种全新的方法会是一个更好的主意......任何建议?

Conceptually, I would say, Maven is designed around the POM file which is a model of the project that is being built. 从概念上讲,我想说,Maven是围绕POM文件设计的,POM文件是正在构建的项目的模型。 It is not so much a process description that applies a function to an input and results in an output on basis of that. 它不是一个将函数应用于输入并在此基础上产生输出的过程描述。

That being said, there is a lot possible with properties in the POM, which then can be passed along on the command-line: -Dproperty=value . 话虽如此,POM中的properties有很多可能,然后可以在命令行上传递: -Dproperty=value It looks as if you would be able to pass the property to whatever process is generating the source code. 看起来您可以将属性传递给生成源代码的任何进程。

I may express some caution, though. 不过,我可能会表示谨慎。 I'm seeing some possible red flags in the overall design that you describe. 我在你描述的整体设计中看到了一些可能的危险信号。 If modules (regardless of their inheritance relationship) pass along files/folders, that should preferably go through install ation. 如果模块(无论它们的继承关系如何)传递文件/文件夹,那么最好通过install So, if you were to do that, you end up with a version of the parent project in your local repository of which you don't really know what it is. 因此,如果您这样做,最终会在本地存储库中找到父项目的一个版本,而您实际上并不知道它是什么。 Which parameters were used? 使用了哪些参数? And how will a user of that artifact then deal with that? 然后,该工件的用户将如何处理?

I'm not saying this won't work, but it may get hairy and not play entirely well within more traditional Maven implementations. 我不是说这不起作用,但它可能会变得毛茸茸,而且在更传统的Maven实现中不能完全发挥。

I'm not entirely sure I understand your use cases but you might want to look at: 我不完全确定我理解你的用例,但你可能想看看:

  • POM Inheritance : Defining as much as you can in the parent module (different groups of modules can have the same parent) POM继承 :在父模块中尽可能多地定义(不同的模块组可以具有相同的父模块)
  • Maven profiles : you can activate based on all sort of potential conventions like even the project name. Maven配置文件 :您可以根据所有类型的潜在约定激活,甚至是项目名称。
  • Maven Archetypes : And finally I think based on what your saying this maybe the only solution of a reusable project template Maven Archetypes :最后我认为根据你的说法,这可能是可重用项目模板的唯一解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM