I'm putting together a maven archetype that has a bunch of custom properties that are used to filter the various archetype resources. I have these specified with defaults in the archetype-metadata.xml e.g.
<requiredProperties> <requiredProperty key="application-name"> <defaultValue>Some Application</defaultValue> </requiredProperty>> </requiredProperties> However when I try to create a project with the archetype, it does not allow me to change these interactively. For instance, it asks for the version with default as follows
Define value for property 'version': 1.0-SNAPSHOT: allowing a version to be entered, but defaulting to 1.0-SNAPSHOT if nothing is entered. For my custom properties, it merely displays them prior to creating the new project
[INFO] Using property: application-name = Some Application If I omit the default value from the archetype-metadata.xml then it will prompt me for a value, but there is no default.
Is it possible to supply a default and still get prompted?
6 Answers
In short, no, it isn't possible. There's a JIRA issue on this. If it is a problem for you, you may want to vote for it.
please look for a final question to commit the settings. In my case there is a final question:
: Confirm properties configuration: groupId: .... Y: : If i enter n then all properties will be re-ask interactive with my defaults from archetype-metadata.xml.
Here is my console part:
Choose archetype: 1: file:///C:\Aktentasche\_daten\m3 -> maven-dsl-project-archet... Choose a number: : 1 Downloading: file:///C:\Aktentasche\_daten\m3/net/sf/maven/plug... data.xml [INFO] Using property: groupId = net.sf.maven.plugins [INFO] Using property: artifactId = dslexample [INFO] Using property: version = 1.0.0-SNAPSHOT [INFO] Using property: package = net.sf.maven.plugins [INFO] Using property: eclipse_platform = helios [INFO] Using property: tycho_version = 0.8.0 Confirm properties configuration: groupId: net.sf.maven.plugins artifactId: dslexample version: 1.0.0-SNAPSHOT package: net.sf.maven.plugins eclipse_platform: helios tycho_version: 0.8.0 Y: : Here i must enter n for interactive dialog with defaults.
I know this is far from ideal but if you provide the default value for all the requiredProperty (including groupId, artifactId, version and package) you will be propted with the resume and then by entering n you will achieve your goal
I raised this on the Maven mailing list but got no reply. As a workaround in the meantime, system properties can be used to override them at the command line when the archetype is run
e.g. -Dapplication-name="Some Application" I've been using this hack, not sure if it's the best way to do it but the only way I've found so far:
${artifactId.replaceAll(".+", "Some Application")} 1Did you try taking the second carat off the ending requiredProperty?
Change </requiredProperty>> to </requiredProperty>
Looks like possibly malformed XML issue.