I'm trying to add additional variables to my archetype. Specifically, my archetype contains a logback.xml file, and I want to populate the log filename with the name of the project I'm generating from the archetype.
I was carrying out the instructions in the answer here Passing extra properties to maven archetype:generate, but it says to add a <requiredProperties>
element to my archetype-metadata.xml. My archetype doesn't have an archetype-metadata.xml, it only has an archetype.xml (which was generated automatically when I generated my archetype from maven-archetype-archetype).
In https://maven.apache.org/guides/mini/guide-creating-archetypes.html, Maven refers to archetype.xml as an artifact-descriptor.
I googled archetype-metadata.xml, and found this - http://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html. Maven calls it an archetype-descriptor as well, but its specification does not contain the id and resources elements that I see in my archetype.xml.
Are archetype.xml and archetype-metadata.xml the same thing? if not, what are their different purposes? Can I add a <requiredProperties>
element to my archetype.xml file? Or should I create an archetype-metadata.xml file?
You should create the archetype descriptor (archetype-metadata.xml) as I suggested in the mentioned post,
Passing extra properties to maven archetype:generate
Here are the steps that I'm executing to generate the project:
mkdir temp
cd temp
git clone git@github.com:jibbyj/appArchetype.git
cd appArchetype
mvn clean install
mkdir run01
cd run01
ls
mvn archetype:generate \
-DarchetypeGroupId=com.company.archetype \
-DarchetypeArtifactId=appArchetype \
-DarchetypeVersion=1.2-SNAPSHOT \
-DarchetypeCatalog=local \
-DinteractiveMode=false \
-DgroupId=com.company \
-DartifactId=test \
-DappName=test
after this flow is completed, in test folder you can find the generated project.
In the pom.xml
, the artifactId is set to the "test", also in src/main/resources/logback.xml
the substitution is made.
The main takeaway from the accepted answer above was to use archetype-metadata.xml instead of archetype.xml, with a <requiredProperties>
element, as well as a <filesets>
element for the resources I want included. In archetype.xml it was a <resources>
tag. Also give the archetype a <packaging>maven-archetype</packaging>
.
Still not totally clear though what the difference is between archetype.xml and archetype-metadata.xml. Assume archetype.xml is deprecated?