Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing extra properties to maven archetype:generate

I've created a Maven archetype for a custom project setup, which is working wonderfully, but I was wondering if it's possible to pass extra parameters so that I can do some more interesting templating. I tried something like

mvn archetype:generate -DarchetypeCatalog=local -DdbHost=localhost

and put

...
<option name="db.host.config.option" value="${dbHost}" />
...

in my template, but that doesn't seem to work. Is there a way to do this with an archetype?

like image 299
Ceilingfish Avatar asked Aug 11 '10 08:08

Ceilingfish


2 Answers

You just have to mention dbHost as requiredProperty in META-INF/maven/archetype-metadata.xml.

<archetype-descriptor name="basic">
    <requiredProperties>
        <requiredProperty key="dbHost"/>
    </requiredProperties>
</archetype-descriptor>
like image 178
devsprint Avatar answered Nov 15 '22 04:11

devsprint


Although this question is rather old, I'll provide my own experience with Maven 3.04

While generating the archetype from a project (create-from-project), you can pass a property file as an argument. Every single property (key=value) passed in will in turn generate a requiredProperty in the archetype-metadata.xml file, with "value" as its default value.
On the other hand, the archetype generation process will look for the string "value" in our text files and replace it by "${key}" (i.e. dbHost=db.host.config.option would look for "db.host.config.option" and replace it by ${dbHost}).

While using the archetype for the final project generation (with generate) we are offered the chance to provide a value for this parameter, with -Dkey=value. So there is no need to edit the archetype-metadata.xml file by hand.

like image 44
magarciaschopohl Avatar answered Nov 15 '22 04:11

magarciaschopohl