Passing extra properties to maven archetype:generate

Ceilingfish picture Ceilingfish · Aug 11, 2010 · Viewed 13.5k times · Source

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?

Answer

devsprint picture devsprint · Sep 26, 2010

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>