简体   繁体   中英

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. The procedure of the build stays the same but I want to be able to produce different output depending on the input UML model.

I have a multi-module project that builds several jars based upon an UML model. The pom structure looks as follows:

+ generation
  - mod1
  - mod2
  - mod3

The root pom (generation) generates java sourcecode (.java) based upon an UML model stored in the directory /uml. Afterwards the modules (mod1...3) compile distinct subsets of this sourcecode and package the output as jar.

I want to reuse this build procedure and apply it to different UML models. How can I reuse the entire generation, compilation and packaging procedure defined in the multimodule project in other maven projects?

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

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)
  • Maven profiles : you can activate based on all sort of potential conventions like even the project name.
  • Maven Archetypes : And finally I think based on what your saying this maybe the only solution of a reusable project template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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